{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Import packages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from pypfopt.efficient_frontier import EfficientFrontier\n",
    "from pypfopt import risk_models\n",
    "from pypfopt.risk_models import CovarianceShrinkage\n",
    "from pypfopt import expected_returns\n",
    "from datetime import datetime\n",
    "from pandas.tseries.offsets import BDay"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "import pickle"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1. Read Input Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_price = pd.read_csv(\"sp500_price_19960101_20221021.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(6217423, 45)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_price.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_price['adj_price'] = df_price['prccd'] / df_price['ajexdi']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_price = df_price[[\"gvkey\", \"datadate\", 'adj_price']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "982"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(df_price.gvkey.unique())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "selected_stock = pd.read_csv(\"stock_selected.csv\",index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "selected_stock=selected_stock[selected_stock.trade_date>='2018-03-01'].reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3870, 3)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "selected_stock.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gvkey</th>\n",
       "      <th>predicted_return</th>\n",
       "      <th>trade_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1678</td>\n",
       "      <td>0.013570</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4430</td>\n",
       "      <td>0.012420</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4503</td>\n",
       "      <td>0.002985</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6788</td>\n",
       "      <td>0.033034</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7912</td>\n",
       "      <td>0.012037</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   gvkey  predicted_return  trade_date\n",
       "0   1678          0.013570  2018-03-01\n",
       "1   4430          0.012420  2018-03-01\n",
       "2   4503          0.002985  2018-03-01\n",
       "3   6788          0.033034  2018-03-01\n",
       "4   7912          0.012037  2018-03-01"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "selected_stock.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2. Get trade date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of unique stocks selected:  644\n"
     ]
    }
   ],
   "source": [
    "print(\"Number of unique stocks selected: \", len(selected_stock.gvkey.unique()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "all_date=df_price.datadate.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6886"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(all_date)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "trade_date=selected_stock.trade_date.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['2018-03-01', '2018-06-01', '2018-09-01', '2018-12-01',\n",
       "       '2019-03-01', '2019-06-01', '2019-09-01', '2019-12-01',\n",
       "       '2020-03-01', '2020-06-01', '2020-09-01', '2020-12-01',\n",
       "       '2021-03-01', '2021-06-01', '2021-09-01', '2021-12-01',\n",
       "       '2022-03-01', '2022-06-01', '2022-09-01'], dtype=object)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "trade_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of trade dates 19\n"
     ]
    }
   ],
   "source": [
    "print(\"Number of trade dates\", len(trade_date))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3. Get daily 1 year return table in each 89 trade period"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gvkey</th>\n",
       "      <th>predicted_return</th>\n",
       "      <th>trade_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1678</td>\n",
       "      <td>0.013570</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4430</td>\n",
       "      <td>0.012420</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4503</td>\n",
       "      <td>0.002985</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6788</td>\n",
       "      <td>0.033034</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7912</td>\n",
       "      <td>0.012037</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   gvkey  predicted_return  trade_date\n",
       "0   1678          0.013570  2018-03-01\n",
       "1   4430          0.012420  2018-03-01\n",
       "2   4503          0.002985  2018-03-01\n",
       "3   6788          0.033034  2018-03-01\n",
       "4   7912          0.012037  2018-03-01"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "selected_stock.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Time consuming:  1.1987383445103963  minutes\n"
     ]
    }
   ],
   "source": [
    "# took about 9 minutes to run\n",
    "start = time.time()\n",
    "all_return_table={}\n",
    "#all_predicted_return={}\n",
    "all_stocks_info = {}\n",
    "#for i in range(0,1):\n",
    "for i in range(len(trade_date)):\n",
    "    #match trading date\n",
    "    index = selected_stock.trade_date==trade_date[i]\n",
    "    #get the corresponding trade period's selected stocks' name\n",
    "    stocks_name=selected_stock.gvkey[selected_stock.trade_date==trade_date[i]].values\n",
    "    temp_info = selected_stock[selected_stock.trade_date==trade_date[i]]\n",
    "    temp_info = temp_info.reset_index()\n",
    "    del temp_info['index']\n",
    "    all_stocks_info[trade_date[i]] = temp_info\n",
    "    #get the corresponding trade period's selected stocks' predicted return\n",
    "    asset_expected_return=selected_stock[index].predicted_return.values\n",
    "    \n",
    "    \n",
    "    #determine the business date\n",
    "    #print(convert_to_yyyymmdd)\n",
    "    tradedate = pd.to_datetime(trade_date[i])\n",
    "    ts = datetime(tradedate.year-1, tradedate.month, tradedate.day)\n",
    "    bd = pd.tseries.offsets.BusinessDay(n =1) \n",
    "    new_timestamp = ts - bd \n",
    "    all_date = pd.to_datetime(all_date, format=\"%Y%m%d\")\n",
    "    get_date_index=(all_date<tradedate) & (all_date>new_timestamp)\n",
    "    get_date=all_date[get_date_index]\n",
    "    #get adjusted price table\n",
    "    return_table=pd.DataFrame()\n",
    "    for m in range(len(stocks_name)):\n",
    "        #get stocks's name\n",
    "        index_tic=(df_price.gvkey==stocks_name[m])\n",
    "        #get this stock's all historicall price from sp500_price\n",
    "        sp500_temp=df_price[index_tic]\n",
    "        merge_left_data_table = pd.DataFrame(get_date)\n",
    "        merge_left_data_table.columns = ['datadate']\n",
    "        #print(merge_left_data_table)\n",
    "        sp500_temp.datadate = pd.to_datetime(sp500_temp.datadate, format=\"%Y%m%d\")\n",
    "        temp_price=merge_left_data_table.merge(sp500_temp, on=['datadate'], how='left')\n",
    "        \n",
    "        temp_price = temp_price.dropna()\n",
    "        temp_price['daily_return']=temp_price.adj_price.pct_change()\n",
    "        return_table=return_table.append(temp_price,ignore_index=True)\n",
    "    all_return_table[trade_date[i]] = return_table\n",
    "end = time.time()\n",
    "print(\"Time consuming: \", (end-start)/60, \" minutes\")\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "check=all_stocks_info['2018-03-01'].gvkey.unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in check:\n",
    "    if i not in all_return_table['2018-03-01'].gvkey.unique():\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gvkey</th>\n",
       "      <th>datadate</th>\n",
       "      <th>adj_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1045</td>\n",
       "      <td>19960102</td>\n",
       "      <td>37.5625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1045</td>\n",
       "      <td>19960103</td>\n",
       "      <td>38.4375</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1045</td>\n",
       "      <td>19960104</td>\n",
       "      <td>37.6875</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1045</td>\n",
       "      <td>19960105</td>\n",
       "      <td>37.3125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1045</td>\n",
       "      <td>19960108</td>\n",
       "      <td>36.7500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   gvkey  datadate  adj_price\n",
       "0   1045  19960102    37.5625\n",
       "1   1045  19960103    38.4375\n",
       "2   1045  19960104    37.6875\n",
       "3   1045  19960105    37.3125\n",
       "4   1045  19960108    36.7500"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_price.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gvkey</th>\n",
       "      <th>predicted_return</th>\n",
       "      <th>trade_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>382</th>\n",
       "      <td>34443</td>\n",
       "      <td>0.024301</td>\n",
       "      <td>2021-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>393</th>\n",
       "      <td>34443</td>\n",
       "      <td>0.010315</td>\n",
       "      <td>2021-06-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>404</th>\n",
       "      <td>34443</td>\n",
       "      <td>0.016737</td>\n",
       "      <td>2021-09-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     gvkey  predicted_return  trade_date\n",
       "382  34443          0.024301  2021-03-01\n",
       "393  34443          0.010315  2021-06-01\n",
       "404  34443          0.016737  2021-09-01"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "selected_stock[selected_stock.gvkey==34443]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gvkey</th>\n",
       "      <th>datadate</th>\n",
       "      <th>adj_price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4857154</th>\n",
       "      <td>34443</td>\n",
       "      <td>20190320</td>\n",
       "      <td>49.80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4857155</th>\n",
       "      <td>34443</td>\n",
       "      <td>20190321</td>\n",
       "      <td>48.98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4857156</th>\n",
       "      <td>34443</td>\n",
       "      <td>20190322</td>\n",
       "      <td>48.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4857157</th>\n",
       "      <td>34443</td>\n",
       "      <td>20190325</td>\n",
       "      <td>49.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4857158</th>\n",
       "      <td>34443</td>\n",
       "      <td>20190326</td>\n",
       "      <td>48.85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4858056</th>\n",
       "      <td>34443</td>\n",
       "      <td>20221017</td>\n",
       "      <td>45.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4858057</th>\n",
       "      <td>34443</td>\n",
       "      <td>20221018</td>\n",
       "      <td>46.38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4858058</th>\n",
       "      <td>34443</td>\n",
       "      <td>20221019</td>\n",
       "      <td>45.13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4858059</th>\n",
       "      <td>34443</td>\n",
       "      <td>20221020</td>\n",
       "      <td>44.93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4858060</th>\n",
       "      <td>34443</td>\n",
       "      <td>20221021</td>\n",
       "      <td>46.87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>907 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         gvkey  datadate  adj_price\n",
       "4857154  34443  20190320      49.80\n",
       "4857155  34443  20190321      48.98\n",
       "4857156  34443  20190322      48.60\n",
       "4857157  34443  20190325      49.15\n",
       "4857158  34443  20190326      48.85\n",
       "...        ...       ...        ...\n",
       "4858056  34443  20221017      45.26\n",
       "4858057  34443  20221018      46.38\n",
       "4858058  34443  20221019      45.13\n",
       "4858059  34443  20221020      44.93\n",
       "4858060  34443  20221021      46.87\n",
       "\n",
       "[907 rows x 3 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_price[df_price.gvkey==34443]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Save to pickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('all_return_table.pickle', 'wb') as handle: \n",
    "    pickle.dump(all_return_table, handle, protocol=pickle.HIGHEST_PROTOCOL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('all_stocks_info.pickle', 'wb') as handle:\n",
    "    pickle.dump(all_stocks_info, handle, protocol=pickle.HIGHEST_PROTOCOL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('all_return_table.pickle', 'rb') as handle:\n",
    "    all_return_table = pickle.load(handle)\n",
    "\n",
    "with open('all_stocks_info.pickle', 'rb') as handle:\n",
    "    all_stocks_info = pickle.load(handle)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(all_stocks_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datadate</th>\n",
       "      <th>gvkey</th>\n",
       "      <th>adj_price</th>\n",
       "      <th>daily_return</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-03-01</td>\n",
       "      <td>1678.0</td>\n",
       "      <td>52.95</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-03-02</td>\n",
       "      <td>1678.0</td>\n",
       "      <td>51.92</td>\n",
       "      <td>-0.019452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-03-03</td>\n",
       "      <td>1678.0</td>\n",
       "      <td>52.09</td>\n",
       "      <td>0.003274</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-03-06</td>\n",
       "      <td>1678.0</td>\n",
       "      <td>52.19</td>\n",
       "      <td>0.001920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-03-07</td>\n",
       "      <td>1678.0</td>\n",
       "      <td>51.28</td>\n",
       "      <td>-0.017436</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55430</th>\n",
       "      <td>2018-02-22</td>\n",
       "      <td>260774.0</td>\n",
       "      <td>44.78</td>\n",
       "      <td>0.006745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55431</th>\n",
       "      <td>2018-02-23</td>\n",
       "      <td>260774.0</td>\n",
       "      <td>45.95</td>\n",
       "      <td>0.026128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55432</th>\n",
       "      <td>2018-02-26</td>\n",
       "      <td>260774.0</td>\n",
       "      <td>46.64</td>\n",
       "      <td>0.015016</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55433</th>\n",
       "      <td>2018-02-27</td>\n",
       "      <td>260774.0</td>\n",
       "      <td>47.07</td>\n",
       "      <td>0.009220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55434</th>\n",
       "      <td>2018-02-28</td>\n",
       "      <td>260774.0</td>\n",
       "      <td>46.75</td>\n",
       "      <td>-0.006798</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>55435 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        datadate     gvkey  adj_price  daily_return\n",
       "0     2017-03-01    1678.0      52.95           NaN\n",
       "1     2017-03-02    1678.0      51.92     -0.019452\n",
       "2     2017-03-03    1678.0      52.09      0.003274\n",
       "3     2017-03-06    1678.0      52.19      0.001920\n",
       "4     2017-03-07    1678.0      51.28     -0.017436\n",
       "...          ...       ...        ...           ...\n",
       "55430 2018-02-22  260774.0      44.78      0.006745\n",
       "55431 2018-02-23  260774.0      45.95      0.026128\n",
       "55432 2018-02-26  260774.0      46.64      0.015016\n",
       "55433 2018-02-27  260774.0      47.07      0.009220\n",
       "55434 2018-02-28  260774.0      46.75     -0.006798\n",
       "\n",
       "[55435 rows x 4 columns]"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all_return_table['2018-03-01']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "19"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(all_return_table)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gvkey</th>\n",
       "      <th>predicted_return</th>\n",
       "      <th>trade_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1678</td>\n",
       "      <td>0.013570</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4430</td>\n",
       "      <td>0.012420</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>4503</td>\n",
       "      <td>0.002985</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6788</td>\n",
       "      <td>0.033034</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7912</td>\n",
       "      <td>0.012037</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>175</th>\n",
       "      <td>32580</td>\n",
       "      <td>0.046215</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>176</th>\n",
       "      <td>65290</td>\n",
       "      <td>0.020053</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>177</th>\n",
       "      <td>65640</td>\n",
       "      <td>0.045059</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <td>110179</td>\n",
       "      <td>0.020612</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>179</th>\n",
       "      <td>260774</td>\n",
       "      <td>0.022298</td>\n",
       "      <td>2018-03-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>180 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      gvkey  predicted_return  trade_date\n",
       "0      1678          0.013570  2018-03-01\n",
       "1      4430          0.012420  2018-03-01\n",
       "2      4503          0.002985  2018-03-01\n",
       "3      6788          0.033034  2018-03-01\n",
       "4      7912          0.012037  2018-03-01\n",
       "..      ...               ...         ...\n",
       "175   32580          0.046215  2018-03-01\n",
       "176   65290          0.020053  2018-03-01\n",
       "177   65640          0.045059  2018-03-01\n",
       "178  110179          0.020612  2018-03-01\n",
       "179  260774          0.022298  2018-03-01\n",
       "\n",
       "[180 rows x 3 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all_stocks_info['2018-03-01']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 4. Potfolio Optimization using pypfopt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      gvkey  predicted_return  trade_date\n",
      "0      1230          0.026920  2018-03-01\n",
      "1      1678          0.013570  2018-03-01\n",
      "2      1722          0.035988  2018-03-01\n",
      "3      2574          0.035439  2018-03-01\n",
      "4      2751          0.028170  2018-03-01\n",
      "..      ...               ...         ...\n",
      "175  254338          0.033301  2018-03-01\n",
      "176  260774          0.022298  2018-03-01\n",
      "177  270281          0.027811  2018-03-01\n",
      "178  287882          0.026155  2018-03-01\n",
      "179  294524          0.026678  2018-03-01\n",
      "\n",
      "[180 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2017-03-01    1678.0      52.95           NaN\n",
      "1     2017-03-02    1678.0      51.92     -0.019452\n",
      "2     2017-03-03    1678.0      52.09      0.003274\n",
      "3     2017-03-06    1678.0      52.19      0.001920\n",
      "4     2017-03-07    1678.0      51.28     -0.017436\n",
      "...          ...       ...        ...           ...\n",
      "55430 2018-02-22  260774.0      44.78      0.006745\n",
      "55431 2018-02-23  260774.0      45.95      0.026128\n",
      "55432 2018-02-26  260774.0      46.64      0.015016\n",
      "55433 2018-02-27  260774.0      47.07      0.009220\n",
      "55434 2018-02-28  260774.0      46.75     -0.006798\n",
      "\n",
      "[55435 rows x 4 columns]\n",
      "cleaned_weights_min:  OrderedDict([(4611.0, 0.00531), (7171.0, 0.00531), (17928.0, 0.00532), (9225.0, 0.00531), (2574.0, 0.00531), (178704.0, 0.00531), (124434.0, 0.00531), (189459.0, 0.00532), (31774.0, 0.00531), (4640.0, 0.00531), (18465.0, 0.00532), (28192.0, 0.00531), (3107.0, 0.00529), (11300.0, 0.00531), (20004.0, 0.00532), (28195.0, 0.00531), (9258.0, 0.00531), (26156.0, 0.00531), (9777.0, 0.00533), (19000.0, 0.00531), (15417.0, 0.00531), (29241.0, 0.00531), (145977.0, 0.00531), (4674.0, 0.00531), (25157.0, 0.00531), (7750.0, 0.00531), (162887.0, 0.00531), (8264.0, 0.00531), (7241.0, 0.00532), (5709.0, 0.00531), (14418.0, 0.00531), (9299.0, 0.00531), (141913.0, 0.00531), (12892.0, 0.00531), (146017.0, 0.00532), (110179.0, 0.00532), (65640.0, 0.00531), (165993.0, 0.00531), (8810.0, 0.00532), (163946.0, 0.00531), (10860.0, 0.00531), (29804.0, 0.00531), (186989.0, 0.00531), (14960.0, 0.00532), (4093.0, 0.00531), (10867.0, 0.00532), (9846.0, 0.00531), (63099.0, 0.00531), (3708.0, 0.00531), (6781.0, 0.00531), (160893.0, 0.00531), (294524.0, 0.00531), (6788.0, 0.00531), (287882.0, 0.00531), (14477.0, 0.00531), (1678.0, 0.00531), (158354.0, 0.00531), (20116.0, 0.00533), (145046.0, 0.00531), (25753.0, 0.00531), (5786.0, 0.00531), (9882.0, 0.00531), (24731.0, 0.00531), (63643.0, 0.00531), (145049.0, 0.00531), (15520.0, 0.00531), (28320.0, 0.00531), (6821.0, 0.00531), (64166.0, 0.00531), (260774.0, 0.00531), (7343.0, 0.00531), (9904.0, 0.00531), (144559.0, 0.00532), (184498.0, 0.00531), (184500.0, 0.00532), (126136.0, 0.00532), (1722.0, 0.00531), (28349.0, 0.00531), (2751.0, 0.00531), (25279.0, 0.00532), (26304.0, 0.00531), (7875.0, 0.00531), (25283.0, 0.00531), (23238.0, 0.00531), (14535.0, 0.00531), (1230.0, 0.00531), (4818.0, 0.00531), (28385.0, 0.00531), (4839.0, 0.00531), (7912.0, 0.00531), (17639.0, 0.00531), (11506.0, 0.00531), (154357.0, 0.00532), (5878.0, 0.00532), (133366.0, 0.00531), (25338.0, 0.00531), (14590.0, 0.00531), (3336.0, 0.00531), (65290.0, 0.00531), (25356.0, 0.00531), (29968.0, 0.00532), (134932.0, 0.00531), (11032.0, 0.00531), (25880.0, 0.00531), (30490.0, 0.00531), (163610.0, 0.00531), (162076.0, 0.00531), (120093.0, 0.00531), (8479.0, 0.00531), (7970.0, 0.00531), (165675.0, 0.00531), (21808.0, 0.00532), (7985.0, 0.00532), (3897.0, 0.00531), (177983.0, 0.00531), (21825.0, 0.00531), (32580.0, 0.00531), (13125.0, 0.00531), (149318.0, 0.00532), (4430.0, 0.00531), (179534.0, 0.00531), (5968.0, 0.00531), (21841.0, 0.00531), (6994.0, 0.00531), (8530.0, 0.00531), (9555.0, 0.00531), (162129.0, 0.00531), (149337.0, 0.00532), (8539.0, 0.00531), (12635.0, 0.00531), (24925.0, 0.00531), (65886.0, 0.00531), (31587.0, 0.00531), (7525.0, 0.00531), (9063.0, 0.00531), (62823.0, 0.00531), (16245.0, 0.00531), (4988.0, 0.00531), (3964.0, 0.00531), (4990.0, 0.00531), (184700.0, 0.00531), (28034.0, 0.00531), (254338.0, 0.00531), (10631.0, 0.00532), (9611.0, 0.00532), (61325.0, 0.00531), (4494.0, 0.00531), (66446.0, 0.00532), (180112.0, 0.00531), (14225.0, 0.00532), (30098.0, 0.00531), (184725.0, 0.00531), (4503.0, 0.00531), (11672.0, 0.00531), (150937.0, 0.00531), (8606.0, 0.00531), (15267.0, 0.00531), (186278.0, 0.00531), (20904.0, 0.00531), (23978.0, 0.00532), (198058.0, 0.00531), (65967.0, 0.00531), (3505.0, 0.04832), (12726.0, 0.00529), (270281.0, 0.00531), (185291.0, 0.00531), (61388.0, 0.00531), (26061.0, 0.00531), (10190.0, 0.00531), (5071.0, 0.00531), (12756.0, 0.00531), (28118.0, 0.00531), (66016.0, 0.00531), (160225.0, 0.00531), (60900.0, 0.00531), (180711.0, 0.00529), (7146.0, 0.00583), (15855.0, 0.00531), (166385.0, 0.00532), (6653.0, 0.00531)])\n",
      "2018-03-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1177          0.031299  2018-06-01\n",
      "1      1327          0.029118  2018-06-01\n",
      "2      1440          0.016027  2018-06-01\n",
      "3      1487          0.018870  2018-06-01\n",
      "4      1602          0.030746  2018-06-01\n",
      "..      ...               ...         ...\n",
      "175  189459          0.022895  2018-06-01\n",
      "176  254338          0.044710  2018-06-01\n",
      "177  260774          0.022255  2018-06-01\n",
      "178  287882          0.026092  2018-06-01\n",
      "179  294524          0.020524  2018-06-01\n",
      "\n",
      "[180 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2017-06-01    1678.0      47.30           NaN\n",
      "1     2017-06-02    1678.0      46.99     -0.006554\n",
      "2     2017-06-05    1678.0      46.73     -0.005533\n",
      "3     2017-06-06    1678.0      48.04      0.028033\n",
      "4     2017-06-07    1678.0      46.78     -0.026228\n",
      "...          ...       ...        ...           ...\n",
      "59715 2018-05-24  260774.0      47.75     -0.002090\n",
      "59716 2018-05-25  260774.0      47.56     -0.003979\n",
      "59717 2018-05-29  260774.0      46.59     -0.020395\n",
      "59718 2018-05-30  260774.0      47.08      0.010517\n",
      "59719 2018-05-31  260774.0      46.19     -0.018904\n",
      "\n",
      "[59720 rows x 4 columns]\n",
      "cleaned_weights_min:  OrderedDict([(11264.0, 0.00532), (9225.0, 0.00521), (2574.0, 0.00529), (189459.0, 0.00528), (28180.0, 0.00533), (8215.0, 0.00533), (165914.0, 0.00538), (4640.0, 0.00529), (18465.0, 0.00528), (28192.0, 0.00528), (3107.0, 0.0053), (11300.0, 0.0053), (3619.0, 0.00527), (28195.0, 0.00529), (26156.0, 0.00526), (3121.0, 0.00528), (9777.0, 0.00529), (161844.0, 0.00532), (9783.0, 0.00528), (145977.0, 0.00533), (8762.0, 0.0053), (1602.0, 0.00535), (4674.0, 0.00528), (7750.0, 0.00528), (162887.0, 0.0053), (8264.0, 0.0053), (183366.0, 0.00531), (23627.0, 0.0053), (183377.0, 0.00529), (9299.0, 0.00529), (152149.0, 0.00529), (110179.0, 0.0053), (31846.0, 0.00529), (65640.0, 0.00528), (142953.0, 0.00528), (163946.0, 0.00528), (4093.0, 0.00532), (177267.0, 0.00522), (8823.0, 0.00528), (6268.0, 0.00523), (6781.0, 0.00529), (3708.0, 0.00533), (61567.0, 0.00524), (160893.0, 0.00529), (294524.0, 0.00529), (6788.0, 0.00527), (61574.0, 0.00527), (5256.0, 0.00537), (287882.0, 0.00533), (1678.0, 0.00528), (145552.0, 0.00533), (158354.0, 0.00528), (20116.0, 0.00529), (2710.0, 0.00529), (61591.0, 0.00546), (145046.0, 0.00528), (1177.0, 0.00542), (1690.0, 0.0053), (5786.0, 0.00528), (24731.0, 0.00528), (25753.0, 0.00529), (145049.0, 0.00528), (6304.0, 0.0053), (6821.0, 0.00531), (6310.0, 0.00528), (8358.0, 0.00529), (10920.0, 0.00531), (1704.0, 0.00521), (10405.0, 0.00529), (12459.0, 0.0054), (2220.0, 0.05), (260774.0, 0.00521), (9904.0, 0.00528), (184498.0, 0.00529), (126136.0, 0.00526), (1722.0, 0.00531), (28349.0, 0.00528), (25279.0, 0.00532), (11456.0, 0.0053), (23238.0, 0.0053), (30923.0, 0.00532), (2269.0, 0.00527), (62689.0, 0.00528), (9445.0, 0.00529), (4839.0, 0.00528), (6375.0, 0.00528), (7912.0, 0.00529), (17639.0, 0.00528), (3310.0, 0.00528), (11506.0, 0.0053), (7923.0, 0.00534), (121077.0, 0.00532), (5878.0, 0.00539), (25338.0, 0.00531), (25340.0, 0.0053), (14590.0, 0.00527), (155393.0, 0.00537), (7938.0, 0.00529), (10499.0, 0.0053), (20228.0, 0.00524), (65290.0, 0.00528), (113419.0, 0.00532), (30990.0, 0.00528), (29968.0, 0.00528), (11032.0, 0.00723), (24344.0, 0.0053), (25880.0, 0.0053), (27928.0, 0.00529), (30490.0, 0.00528), (162076.0, 0.00529), (14624.0, 0.00529), (7970.0, 0.00524), (7974.0, 0.00534), (165675.0, 0.00529), (1327.0, 0.00542), (7985.0, 0.00531), (7991.0, 0.00534), (24379.0, 0.00526), (11584.0, 0.0053), (21825.0, 0.00529), (32580.0, 0.00522), (179534.0, 0.00528), (5968.0, 0.00528), (16721.0, 0.00462), (6994.0, 0.00528), (3413.0, 0.00528), (24405.0, 0.00522), (8539.0, 0.0053), (12635.0, 0.0053), (7525.0, 0.00528), (62823.0, 0.00529), (7017.0, 0.00529), (5492.0, 0.00528), (16245.0, 0.00528), (121718.0, 0.00528), (6008.0, 0.00527), (4988.0, 0.00529), (3964.0, 0.0053), (254338.0, 0.0053), (180112.0, 0.00528), (12689.0, 0.00526), (13714.0, 0.00531), (14225.0, 0.00529), (24468.0, 0.0054), (184725.0, 0.00528), (13721.0, 0.00532), (64410.0, 0.00529), (150937.0, 0.00528), (8606.0, 0.00528), (1440.0, 0.00528), (15267.0, 0.00535), (6565.0, 0.00522), (62374.0, 0.0053), (11687.0, 0.00528), (186278.0, 0.0053), (23978.0, 0.00527), (3502.0, 0.00528), (65967.0, 0.0053), (12726.0, 0.00533), (7620.0, 0.00529), (25030.0, 0.00531), (29127.0, 0.00527), (186310.0, 0.0053), (185291.0, 0.00528), (61388.0, 0.00528), (26061.0, 0.0053), (20430.0, 0.00528), (1487.0, 0.00528), (5073.0, 0.00528), (25056.0, 0.00534), (66016.0, 0.00529), (160225.0, 0.00529), (60900.0, 0.00532), (14822.0, 0.0053), (180711.0, 0.00527), (166385.0, 0.00622), (2547.0, 0.00529), (29173.0, 0.00531), (4598.0, 0.0053), (6653.0, 0.00529)])\n",
      "2018-06-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1075          0.020007  2018-09-01\n",
      "1      1230          0.029091  2018-09-01\n",
      "2      1440          0.021822  2018-09-01\n",
      "3      1487          0.028614  2018-09-01\n",
      "4      1602          0.033592  2018-09-01\n",
      "..      ...               ...         ...\n",
      "175  245918          0.042777  2018-09-01\n",
      "176  253501          0.029258  2018-09-01\n",
      "177  254338          0.040259  2018-09-01\n",
      "178  260774          0.026135  2018-09-01\n",
      "179  287882          0.007646  2018-09-01\n",
      "\n",
      "[180 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2017-09-01    1678.0      39.48           NaN\n",
      "1     2017-09-05    1678.0      39.42     -0.001520\n",
      "2     2017-09-06    1678.0      40.13      0.018011\n",
      "3     2017-09-07    1678.0      40.73      0.014951\n",
      "4     2017-09-08    1678.0      39.30     -0.035109\n",
      "...          ...       ...        ...           ...\n",
      "57662 2018-08-27  260774.0      47.97      0.008621\n",
      "57663 2018-08-28  260774.0      48.34      0.007713\n",
      "57664 2018-08-29  260774.0      47.95     -0.008068\n",
      "57665 2018-08-30  260774.0      48.05      0.002086\n",
      "57666 2018-08-31  260774.0      48.81      0.015817\n",
      "\n",
      "[57667 rows x 4 columns]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cleaned_weights_min:  OrderedDict([(11264.0, 0.00532), (6669.0, 0.00532), (2574.0, 0.00532), (189459.0, 0.00532), (8215.0, 0.0053), (6682.0, 0.00532), (4640.0, 0.00532), (28192.0, 0.00532), (3107.0, 0.00532), (11300.0, 0.00532), (20004.0, 0.00533), (29736.0, 0.00532), (10793.0, 0.00534), (10795.0, 0.00533), (26156.0, 0.00532), (61483.0, 0.00532), (1075.0, 0.00533), (30259.0, 0.00533), (15414.0, 0.00532), (9783.0, 0.00532), (253501.0, 0.00532), (1602.0, 0.00533), (25157.0, 0.00532), (28742.0, 0.00532), (162887.0, 0.00532), (3144.0, 0.00532), (23627.0, 0.00532), (183377.0, 0.00533), (9299.0, 0.00532), (152149.0, 0.00532), (12892.0, 0.00532), (110179.0, 0.00532), (12389.0, 0.00532), (65640.0, 0.00532), (163946.0, 0.00532), (186989.0, 0.00533), (4093.0, 0.00533), (5234.0, 0.00532), (10867.0, 0.00534), (177267.0, 0.00532), (9846.0, 0.00531), (8823.0, 0.00533), (64630.0, 0.00532), (63099.0, 0.00533), (6781.0, 0.00532), (160893.0, 0.00532), (2176.0, 0.00533), (61574.0, 0.00532), (11399.0, 0.00533), (287882.0, 0.00532), (1678.0, 0.00532), (158354.0, 0.00532), (20116.0, 0.00532), (2710.0, 0.00532), (61591.0, 0.00533), (145046.0, 0.00533), (1690.0, 0.00532), (5786.0, 0.00532), (9882.0, 0.00532), (24731.0, 0.00532), (245918.0, 0.00532), (6304.0, 0.00532), (10405.0, 0.00532), (260774.0, 0.00532), (1704.0, 0.00532), (10920.0, 0.00532), (12459.0, 0.00532), (2220.0, 0.00536), (9904.0, 0.00532), (184498.0, 0.00532), (1722.0, 0.00532), (7866.0, 0.00532), (13498.0, 0.00533), (28349.0, 0.00532), (199356.0, 0.00532), (25283.0, 0.00532), (7366.0, 0.00533), (14535.0, 0.00532), (30923.0, 0.00532), (1230.0, 0.00532), (175319.0, 0.00532), (28385.0, 0.00532), (9445.0, 0.00533), (4839.0, 0.00532), (6375.0, 0.00532), (7912.0, 0.00532), (10983.0, 0.00532), (17639.0, 0.00532), (61676.0, 0.00533), (7921.0, 0.00533), (11506.0, 0.00532), (121077.0, 0.00532), (25338.0, 0.00532), (24316.0, 0.00532), (25340.0, 0.00533), (14590.0, 0.00531), (140541.0, 0.00532), (2817.0, 0.0053), (1794.0, 0.00532), (7938.0, 0.00533), (10499.0, 0.00533), (155393.0, 0.00533), (65290.0, 0.00532), (7435.0, 0.00533), (8972.0, 0.00532), (25356.0, 0.00532), (30990.0, 0.00532), (29968.0, 0.00532), (134932.0, 0.00532), (11032.0, 0.00537), (24344.0, 0.00532), (25880.0, 0.00533), (162076.0, 0.00532), (120093.0, 0.00532), (8479.0, 0.00532), (7970.0, 0.00532), (26410.0, 0.00532), (20779.0, 0.0053), (61739.0, 0.00532), (7991.0, 0.00532), (24379.0, 0.00532), (11584.0, 0.00532), (21825.0, 0.00532), (32580.0, 0.0053), (13125.0, 0.00533), (179534.0, 0.00533), (5968.0, 0.00532), (21841.0, 0.00532), (6994.0, 0.00532), (8539.0, 0.00532), (12635.0, 0.00533), (114524.0, 0.00532), (7525.0, 0.00532), (9063.0, 0.00532), (7017.0, 0.00532), (11636.0, 0.00532), (16245.0, 0.00532), (10614.0, 0.00532), (121718.0, 0.00532), (6008.0, 0.00532), (4988.0, 0.00533), (184700.0, 0.00532), (4990.0, 0.00532), (28034.0, 0.00531), (254338.0, 0.00533), (61325.0, 0.00532), (180112.0, 0.00532), (12689.0, 0.00532), (14225.0, 0.00533), (30098.0, 0.00532), (4503.0, 0.00532), (13721.0, 0.00531), (64410.0, 0.00532), (8606.0, 0.00532), (1440.0, 0.00533), (15267.0, 0.00532), (62374.0, 0.00533), (186278.0, 0.00532), (23978.0, 0.00533), (65967.0, 0.00532), (3505.0, 0.04703), (12726.0, 0.00532), (30137.0, 0.00533), (25030.0, 0.00532), (29127.0, 0.00532), (26061.0, 0.00532), (20430.0, 0.00532), (1487.0, 0.00532), (5073.0, 0.00532), (128978.0, 0.00533), (12756.0, 0.00532), (29150.0, 0.00532), (66016.0, 0.00533), (160225.0, 0.00532), (180711.0, 0.00532), (166385.0, 0.00543), (2547.0, 0.00533), (9203.0, 0.00532), (29173.0, 0.00532), (6653.0, 0.00532)])\n",
      "2018-09-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1075          0.022999  2018-12-01\n",
      "1      1230          0.030141  2018-12-01\n",
      "2      1300          0.026689  2018-12-01\n",
      "3      1602          0.035825  2018-12-01\n",
      "4      1704          0.030994  2018-12-01\n",
      "..      ...               ...         ...\n",
      "175  184700          0.031699  2018-12-01\n",
      "176  184725          0.034448  2018-12-01\n",
      "177  260774          0.016083  2018-12-01\n",
      "178  287882          0.008964  2018-12-01\n",
      "179  312009          0.003517  2018-12-01\n",
      "\n",
      "[180 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2017-12-01    6310.0      17.41           NaN\n",
      "1     2017-12-01    6310.0      36.17      1.077542\n",
      "2     2017-12-04    6310.0      17.25     -0.523085\n",
      "3     2017-12-04    6310.0      36.14      1.095072\n",
      "4     2017-12-05    6310.0      17.14     -0.525733\n",
      "...          ...       ...        ...           ...\n",
      "63551 2018-11-26  260774.0      43.21      0.011233\n",
      "63552 2018-11-27  260774.0      42.75     -0.010646\n",
      "63553 2018-11-28  260774.0      43.59      0.019649\n",
      "63554 2018-11-29  260774.0      43.14     -0.010323\n",
      "63555 2018-11-30  260774.0      43.68      0.012517\n",
      "\n",
      "[63556 rows x 4 columns]\n",
      "cleaned_weights_min:  OrderedDict([(7171.0, 0.00515), (100873.0, 0.00517), (6669.0, 0.00522), (2574.0, 0.00535), (8215.0, 0.00519), (6682.0, 0.00522), (28192.0, 0.00518), (3107.0, 0.00521), (11300.0, 0.00521), (20004.0, 0.00519), (28195.0, 0.00516), (10793.0, 0.00501), (10795.0, 0.00547), (9777.0, 0.00522), (1075.0, 0.00521), (8247.0, 0.00526), (9783.0, 0.00518), (1602.0, 0.00527), (4674.0, 0.00518), (7750.0, 0.00524), (28742.0, 0.00519), (8264.0, 0.00518), (7241.0, 0.00514), (162887.0, 0.00519), (23627.0, 0.00516), (183366.0, 0.00525), (23119.0, 0.00514), (183377.0, 0.00525), (9299.0, 0.0052), (152149.0, 0.00521), (14934.0, 0.00526), (12892.0, 0.00521), (110179.0, 0.00519), (65640.0, 0.00518), (2154.0, 0.00527), (8810.0, 0.00516), (29804.0, 0.00519), (14960.0, 0.00527), (4093.0, 0.0052), (5234.0, 0.00517), (10867.0, 0.00523), (9846.0, 0.00525), (8823.0, 0.00524), (64630.0, 0.00542), (18043.0, 0.00522), (6268.0, 0.0052), (6781.0, 0.00517), (3708.0, 0.00515), (4737.0, 0.00518), (61574.0, 0.0051), (11399.0, 0.00517), (178310.0, 0.00518), (287882.0, 0.00525), (158354.0, 0.00519), (20116.0, 0.00522), (61591.0, 0.00521), (25753.0, 0.00525), (5786.0, 0.00517), (9882.0, 0.00518), (24731.0, 0.00518), (6304.0, 0.0052), (6821.0, 0.00518), (6310.0, 0.00517), (260774.0, 0.00525), (1704.0, 0.00525), (10920.0, 0.00516), (12459.0, 0.00538), (2220.0, 0.00703), (126136.0, 0.00521), (1722.0, 0.00523), (7866.0, 0.00516), (28349.0, 0.00518), (11456.0, 0.00515), (312009.0, 0.00519), (10443.0, 0.0052), (30923.0, 0.00521), (1230.0, 0.00521), (3278.0, 0.00518), (20686.0, 0.00518), (164046.0, 0.00515), (175319.0, 0.00513), (4839.0, 0.00516), (7912.0, 0.00509), (17639.0, 0.00517), (11506.0, 0.00515), (7923.0, 0.00534), (5878.0, 0.00532), (25338.0, 0.00508), (24316.0, 0.00519), (25340.0, 0.00524), (14590.0, 0.0052), (7938.0, 0.00519), (10499.0, 0.00527), (23812.0, 0.00512), (8455.0, 0.00516), (65290.0, 0.00518), (7435.0, 0.00523), (18699.0, 0.00521), (25356.0, 0.00519), (30990.0, 0.00518), (29968.0, 0.00519), (1300.0, 0.00522), (134932.0, 0.00516), (24344.0, 0.0053), (24856.0, 0.00509), (162076.0, 0.00516), (120093.0, 0.00517), (8479.0, 0.00518), (176928.0, 0.0052), (7970.0, 0.00527), (20779.0, 0.00518), (61739.0, 0.00524), (7991.0, 0.00517), (24379.0, 0.00519), (11584.0, 0.00516), (21825.0, 0.0052), (32580.0, 0.00465), (13125.0, 0.00516), (179534.0, 0.00532), (5968.0, 0.00517), (16721.0, 0.00514), (6994.0, 0.00517), (21841.0, 0.00521), (3413.0, 0.00517), (24405.0, 0.0052), (114524.0, 0.00516), (8543.0, 0.00523), (7525.0, 0.00517), (8551.0, 0.00526), (9063.0, 0.00517), (7017.0, 0.00517), (15208.0, 0.00518), (16245.0, 0.00518), (121718.0, 0.00516), (1913.0, 0.00522), (64891.0, 0.0051), (4988.0, 0.00524), (184700.0, 0.00535), (4990.0, 0.00521), (2435.0, 0.00535), (61325.0, 0.00514), (66446.0, 0.00515), (180112.0, 0.00518), (12689.0, 0.00519), (30098.0, 0.00517), (24468.0, 0.00525), (184725.0, 0.00514), (13721.0, 0.00517), (64410.0, 0.00524), (150937.0, 0.0052), (8606.0, 0.00518), (33695.0, 0.00518), (15267.0, 0.00515), (6565.0, 0.00508), (62374.0, 0.00522), (11687.0, 0.00518), (23978.0, 0.00521), (3502.0, 0.0052), (3505.0, 0.05), (7620.0, 0.00519), (25030.0, 0.00522), (29127.0, 0.00517), (3532.0, 0.00516), (26061.0, 0.00516), (20430.0, 0.00518), (61388.0, 0.00519), (5073.0, 0.00517), (12756.0, 0.00516), (6104.0, 0.00504), (122841.0, 0.0052), (138205.0, 0.0055), (29150.0, 0.00515), (66016.0, 0.00524), (160225.0, 0.0052), (180711.0, 0.00519), (104432.0, 0.00526), (166385.0, 0.02335), (9203.0, 0.00522), (29173.0, 0.00517), (6653.0, 0.0052)])\n",
      "2018-12-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1300          0.031119  2019-03-01\n",
      "1      1602          0.031700  2019-03-01\n",
      "2      1704          0.033411  2019-03-01\n",
      "3      1722          0.032640  2019-03-01\n",
      "4      1913          0.019783  2019-03-01\n",
      "..      ...               ...         ...\n",
      "174  260774          0.018402  2019-03-01\n",
      "175  260778          0.031720  2019-03-01\n",
      "176  287882          0.009949  2019-03-01\n",
      "177  312009          0.010056  2019-03-01\n",
      "178  316056          0.030109  2019-03-01\n",
      "\n",
      "[179 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2018-03-01    4503.0      75.20           NaN\n",
      "1     2018-03-02    4503.0      75.55      0.004654\n",
      "2     2018-03-05    4503.0      76.27      0.009530\n",
      "3     2018-03-06    4503.0      76.18     -0.001180\n",
      "4     2018-03-07    4503.0      74.26     -0.025203\n",
      "...          ...       ...        ...           ...\n",
      "63570 2019-02-22  260774.0      50.87      0.005932\n",
      "63571 2019-02-25  260774.0      50.47     -0.007863\n",
      "63572 2019-02-26  260774.0      49.99     -0.009511\n",
      "63573 2019-02-27  260774.0      49.72     -0.005401\n",
      "63574 2019-02-28  260774.0      49.76      0.000805\n",
      "\n",
      "[63575 rows x 4 columns]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cleaned_weights_min:  OrderedDict([(11264.0, 0.00536), (4611.0, 0.00536), (7171.0, 0.00536), (2574.0, 0.00536), (31774.0, 0.00536), (25119.0, 0.00536), (4640.0, 0.00536), (28192.0, 0.00536), (3107.0, 0.00536), (20004.0, 0.00536), (10793.0, 0.00536), (61483.0, 0.00536), (9783.0, 0.00536), (29241.0, 0.00536), (1602.0, 0.00536), (4674.0, 0.00536), (7750.0, 0.00536), (28742.0, 0.00536), (8264.0, 0.00535), (23627.0, 0.00536), (8272.0, 0.00536), (183377.0, 0.00536), (9299.0, 0.00536), (152149.0, 0.00536), (126554.0, 0.00536), (110179.0, 0.00536), (142953.0, 0.00536), (2154.0, 0.00536), (34410.0, 0.00536), (29804.0, 0.00536), (186989.0, 0.00536), (5234.0, 0.00536), (10867.0, 0.00536), (9846.0, 0.00536), (8823.0, 0.00536), (64630.0, 0.00536), (18043.0, 0.00536), (63099.0, 0.00536), (61567.0, 0.00536), (4737.0, 0.00536), (5256.0, 0.00536), (287882.0, 0.00536), (20116.0, 0.00536), (145046.0, 0.00536), (61591.0, 0.00536), (316056.0, 0.00536), (25753.0, 0.00536), (5786.0, 0.00536), (9882.0, 0.00536), (24731.0, 0.00536), (63643.0, 0.00536), (145049.0, 0.00536), (6304.0, 0.00536), (6821.0, 0.00536), (6310.0, 0.00536), (10405.0, 0.00536), (1704.0, 0.00536), (260774.0, 0.00536), (260778.0, 0.00536), (3243.0, 0.00536), (2220.0, 0.04588), (12459.0, 0.00536), (29868.0, 0.00536), (6831.0, 0.00536), (9904.0, 0.00536), (180405.0, 0.00536), (1722.0, 0.00536), (7866.0, 0.00536), (2751.0, 0.00536), (11456.0, 0.00536), (25283.0, 0.00538), (7881.0, 0.00536), (312009.0, 0.00536), (3278.0, 0.00536), (20686.0, 0.00536), (24782.0, 0.00536), (4818.0, 0.00536), (175319.0, 0.00536), (160991.0, 0.00536), (17639.0, 0.00536), (7922.0, 0.00534), (121077.0, 0.00536), (111864.0, 0.00536), (24316.0, 0.00536), (140541.0, 0.00536), (14590.0, 0.00536), (7938.0, 0.00536), (10499.0, 0.00536), (23812.0, 0.00536), (8455.0, 0.00536), (65290.0, 0.00536), (7435.0, 0.00536), (8972.0, 0.00536), (30990.0, 0.00536), (29968.0, 0.00536), (1300.0, 0.00536), (134932.0, 0.00536), (3863.0, 0.00536), (24344.0, 0.00536), (24856.0, 0.00536), (162076.0, 0.00536), (120093.0, 0.00536), (8479.0, 0.00536), (13599.0, 0.00536), (176928.0, 0.00536), (3362.0, 0.00536), (7970.0, 0.00536), (7974.0, 0.00536), (20779.0, 0.00536), (7991.0, 0.00536), (24379.0, 0.00536), (5439.0, 0.00536), (11584.0, 0.00536), (21825.0, 0.00536), (32580.0, 0.00536), (179534.0, 0.00536), (5968.0, 0.00536), (11600.0, 0.00536), (6994.0, 0.00536), (16721.0, 0.00536), (3413.0, 0.00536), (10581.0, 0.00536), (24405.0, 0.00536), (170841.0, 0.00536), (12123.0, 0.00536), (12124.0, 0.00536), (114524.0, 0.00536), (188255.0, 0.00536), (7525.0, 0.00536), (9063.0, 0.00536), (7017.0, 0.00536), (12142.0, 0.00536), (16245.0, 0.00536), (121718.0, 0.00536), (1913.0, 0.00536), (4988.0, 0.00536), (3964.0, 0.00536), (4990.0, 0.00536), (184700.0, 0.00536), (10631.0, 0.00536), (10121.0, 0.00536), (9611.0, 0.00536), (61325.0, 0.00536), (15247.0, 0.00536), (180112.0, 0.00536), (30098.0, 0.00536), (184725.0, 0.00536), (4503.0, 0.00536), (13721.0, 0.00536), (150937.0, 0.00536), (8606.0, 0.00536), (33695.0, 0.0054), (6565.0, 0.00536), (62374.0, 0.00536), (11687.0, 0.00536), (186278.0, 0.00536), (23978.0, 0.00536), (198058.0, 0.00536), (7085.0, 0.00536), (12726.0, 0.00536), (7620.0, 0.00536), (114628.0, 0.00536), (186310.0, 0.00536), (14282.0, 0.00536), (10187.0, 0.00536), (26061.0, 0.00536), (20430.0, 0.00536), (5071.0, 0.00536), (5073.0, 0.00536), (28118.0, 0.00536), (122841.0, 0.00537), (138205.0, 0.00536), (29150.0, 0.00536), (7647.0, 0.00536), (66016.0, 0.00536), (180711.0, 0.00536), (104432.0, 0.00536), (166385.0, 0.00548), (4093.0, 0.00536)])\n",
      "2019-03-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1230          0.022679  2019-06-01\n",
      "1      1300          0.021685  2019-06-01\n",
      "2      1487          0.036372  2019-06-01\n",
      "3      1602          0.035042  2019-06-01\n",
      "4      1722          0.012038  2019-06-01\n",
      "..      ...               ...         ...\n",
      "175  199356          0.035499  2019-06-01\n",
      "176  245918          0.039282  2019-06-01\n",
      "177  260774          0.038713  2019-06-01\n",
      "178  287882          0.002973  2019-06-01\n",
      "179  312009          0.000228  2019-06-01\n",
      "\n",
      "[180 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2018-06-01    4430.0      51.91           NaN\n",
      "1     2018-06-04    4430.0      50.53     -0.026584\n",
      "2     2018-06-05    4430.0      50.73      0.003958\n",
      "3     2018-06-06    4430.0      51.69      0.018924\n",
      "4     2018-06-07    4430.0      53.15      0.028245\n",
      "...          ...       ...        ...           ...\n",
      "60432 2019-05-24  260774.0      48.11      0.016051\n",
      "60433 2019-05-28  260774.0      48.41      0.006236\n",
      "60434 2019-05-29  260774.0      47.22     -0.024582\n",
      "60435 2019-05-30  260774.0      46.27     -0.020119\n",
      "60436 2019-05-31  260774.0      45.70     -0.012319\n",
      "\n",
      "[60437 rows x 4 columns]\n",
      "cleaned_weights_min:  OrderedDict([(4611.0, 0.0053), (10247.0, 0.0053), (6669.0, 0.0053), (2574.0, 0.00532), (189459.0, 0.00535), (8215.0, 0.00531), (6682.0, 0.0053), (4640.0, 0.0053), (28192.0, 0.00529), (3107.0, 0.0053), (11300.0, 0.00531), (20004.0, 0.0053), (24616.0, 0.00528), (10793.0, 0.00531), (162346.0, 0.0053), (26156.0, 0.00531), (30259.0, 0.00531), (8245.0, 0.00529), (9783.0, 0.0053), (187450.0, 0.00525), (1602.0, 0.00529), (3650.0, 0.00531), (4674.0, 0.00529), (7750.0, 0.00531), (162887.0, 0.00527), (8264.0, 0.0053), (7241.0, 0.00529), (23627.0, 0.00533), (5709.0, 0.00535), (183377.0, 0.00531), (9299.0, 0.00528), (152149.0, 0.00531), (12892.0, 0.00531), (146017.0, 0.00536), (110179.0, 0.00527), (31846.0, 0.0053), (29804.0, 0.00536), (186989.0, 0.00534), (10867.0, 0.00531), (6774.0, 0.00528), (9846.0, 0.00528), (64630.0, 0.00544), (18043.0, 0.00531), (3708.0, 0.00533), (6781.0, 0.00529), (63099.0, 0.0056), (61567.0, 0.00533), (4737.0, 0.0053), (6788.0, 0.00529), (61574.0, 0.00531), (5256.0, 0.00541), (133768.0, 0.0053), (287882.0, 0.0053), (145552.0, 0.0053), (158354.0, 0.00529), (20116.0, 0.00541), (145046.0, 0.00532), (61591.0, 0.00536), (25753.0, 0.0053), (145049.0, 0.00529), (24731.0, 0.0053), (245918.0, 0.00537), (6821.0, 0.00529), (6310.0, 0.00529), (8358.0, 0.00532), (10405.0, 0.00529), (260774.0, 0.00529), (3243.0, 0.00529), (12459.0, 0.00531), (6831.0, 0.00537), (9904.0, 0.00535), (180405.0, 0.00537), (1722.0, 0.00528), (7866.0, 0.0053), (165052.0, 0.00527), (28349.0, 0.0053), (199356.0, 0.0053), (2751.0, 0.00528), (11456.0, 0.00528), (7881.0, 0.00531), (11465.0, 0.00539), (30923.0, 0.00531), (312009.0, 0.00529), (1230.0, 0.0053), (4818.0, 0.0053), (175319.0, 0.00528), (2269.0, 0.0053), (160479.0, 0.00531), (24800.0, 0.00564), (4839.0, 0.0053), (17639.0, 0.0053), (61676.0, 0.00528), (2285.0, 0.00555), (121077.0, 0.0053), (25338.0, 0.00531), (24316.0, 0.0053), (25340.0, 0.0053), (14590.0, 0.00529), (140541.0, 0.00531), (10499.0, 0.00529), (8455.0, 0.0053), (65290.0, 0.00529), (30990.0, 0.0053), (29968.0, 0.00529), (1300.0, 0.0053), (134932.0, 0.0053), (24344.0, 0.00539), (24856.0, 0.00529), (25880.0, 0.0053), (27928.0, 0.00532), (162076.0, 0.00532), (13599.0, 0.0053), (176928.0, 0.00529), (3362.0, 0.00532), (7974.0, 0.0053), (20779.0, 0.0053), (7985.0, 0.0053), (7991.0, 0.00529), (62263.0, 0.00532), (5439.0, 0.00536), (21825.0, 0.00531), (34636.0, 0.00532), (4430.0, 0.00528), (179534.0, 0.00533), (5968.0, 0.0053), (11600.0, 0.00531), (6994.0, 0.00529), (16721.0, 0.0053), (3413.0, 0.00529), (24405.0, 0.00533), (8539.0, 0.00519), (12635.0, 0.0053), (7525.0, 0.00529), (9063.0, 0.0053), (7017.0, 0.00531), (12142.0, 0.00534), (5492.0, 0.00531), (3964.0, 0.0053), (184700.0, 0.00538), (4990.0, 0.0053), (157057.0, 0.00539), (2435.0, 0.00563), (31109.0, 0.0053), (10631.0, 0.00527), (180112.0, 0.00529), (12689.0, 0.00531), (24468.0, 0.00532), (105365.0, 0.0053), (4503.0, 0.0053), (13721.0, 0.0053), (64410.0, 0.00531), (150937.0, 0.00532), (8606.0, 0.00529), (15267.0, 0.00524), (62374.0, 0.0053), (186278.0, 0.0053), (23978.0, 0.0053), (12726.0, 0.00534), (114628.0, 0.0053), (25030.0, 0.0053), (186310.0, 0.00531), (185291.0, 0.0053), (61388.0, 0.00531), (26061.0, 0.00529), (20430.0, 0.00529), (1487.0, 0.00529), (5071.0, 0.00533), (5073.0, 0.0053), (128978.0, 0.0053), (7637.0, 0.0053), (122841.0, 0.0053), (138205.0, 0.00532), (66016.0, 0.00535), (160225.0, 0.0053), (180711.0, 0.00528), (166385.0, 0.04865), (2547.0, 0.00538), (9203.0, 0.00532), (138743.0, 0.00532), (4093.0, 0.0053)])\n",
      "2019-06-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1230          0.033096  2019-09-01\n",
      "1      1487          0.030275  2019-09-01\n",
      "2      1602          0.037765  2019-09-01\n",
      "3      1690          0.037136  2019-09-01\n",
      "4      1722          0.016721  2019-09-01\n",
      "..      ...               ...         ...\n",
      "174  245918          0.041429  2019-09-01\n",
      "175  253501          0.033393  2019-09-01\n",
      "176  254338          0.041233  2019-09-01\n",
      "177  260774          0.039417  2019-09-01\n",
      "178  287882          0.005650  2019-09-01\n",
      "\n",
      "[179 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2018-09-04    4430.0      49.30           NaN\n",
      "1     2018-09-05    4430.0      48.77     -0.010751\n",
      "2     2018-09-06    4430.0      46.91     -0.038138\n",
      "3     2018-09-07    4430.0      46.56     -0.007461\n",
      "4     2018-09-10    4430.0      45.97     -0.012672\n",
      "...          ...       ...        ...           ...\n",
      "61294 2019-08-26  260774.0      49.39      0.002639\n",
      "61295 2019-08-27  260774.0      49.33     -0.001215\n",
      "61296 2019-08-28  260774.0      50.11      0.015812\n",
      "61297 2019-08-29  260774.0      51.63      0.030333\n",
      "61298 2019-08-30  260774.0      52.27      0.012396\n",
      "\n",
      "[61299 rows x 4 columns]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cleaned_weights_min:  OrderedDict([(10247.0, 0.00537), (160776.0, 0.00535), (9225.0, 0.00536), (100873.0, 0.00535), (6669.0, 0.00535), (2574.0, 0.00535), (189459.0, 0.00535), (8215.0, 0.00535), (6682.0, 0.00535), (31774.0, 0.00535), (18465.0, 0.00535), (3107.0, 0.00535), (20004.0, 0.00535), (10793.0, 0.00535), (162346.0, 0.00535), (61483.0, 0.00536), (30259.0, 0.00535), (9783.0, 0.00535), (187450.0, 0.00535), (253501.0, 0.00569), (1602.0, 0.00536), (4674.0, 0.00535), (7750.0, 0.00535), (8264.0, 0.00536), (7241.0, 0.00535), (65609.0, 0.00534), (23627.0, 0.00535), (5709.0, 0.00535), (183377.0, 0.00535), (9299.0, 0.00535), (152149.0, 0.00536), (14934.0, 0.00536), (12892.0, 0.00535), (146017.0, 0.00536), (110179.0, 0.00535), (65640.0, 0.00535), (34410.0, 0.00536), (13421.0, 0.00535), (186989.0, 0.00536), (5234.0, 0.00535), (10867.0, 0.00536), (64630.0, 0.00536), (147579.0, 0.00536), (61567.0, 0.00536), (4737.0, 0.00535), (6788.0, 0.00535), (5256.0, 0.00535), (133768.0, 0.00535), (287882.0, 0.00535), (145552.0, 0.00535), (158354.0, 0.00535), (20116.0, 0.00534), (145046.0, 0.00536), (61591.0, 0.00536), (14489.0, 0.00535), (1690.0, 0.00536), (5786.0, 0.00535), (9882.0, 0.00535), (24731.0, 0.00535), (25753.0, 0.00535), (145049.0, 0.00535), (6304.0, 0.00536), (15520.0, 0.00535), (175263.0, 0.00535), (245918.0, 0.00536), (6821.0, 0.00535), (8358.0, 0.00528), (10405.0, 0.00535), (10920.0, 0.00534), (260774.0, 0.00535), (29868.0, 0.00536), (6831.0, 0.00536), (9904.0, 0.00536), (126136.0, 0.00536), (1722.0, 0.00535), (7866.0, 0.00535), (199356.0, 0.00535), (11456.0, 0.00535), (6338.0, 0.00531), (7875.0, 0.00535), (10443.0, 0.00535), (30923.0, 0.00534), (1230.0, 0.00535), (3278.0, 0.00535), (4818.0, 0.00535), (175319.0, 0.00535), (160991.0, 0.00535), (24800.0, 0.00538), (4839.0, 0.00535), (61676.0, 0.00535), (11506.0, 0.00535), (7923.0, 0.00535), (5878.0, 0.00536), (111864.0, 0.00535), (25338.0, 0.00535), (24316.0, 0.00535), (140541.0, 0.00535), (14590.0, 0.00535), (155394.0, 0.00535), (10499.0, 0.00535), (8455.0, 0.00535), (20232.0, 0.00536), (27914.0, 0.00535), (65290.0, 0.00535), (30990.0, 0.00535), (29968.0, 0.00535), (134932.0, 0.00535), (3863.0, 0.00535), (11032.0, 0.00535), (24344.0, 0.00535), (24856.0, 0.00535), (25880.0, 0.00535), (162076.0, 0.00536), (13599.0, 0.00535), (176928.0, 0.00535), (32546.0, 0.00536), (7974.0, 0.00535), (20779.0, 0.00526), (10035.0, 0.00535), (7991.0, 0.00535), (24379.0, 0.00535), (5439.0, 0.00536), (21825.0, 0.00535), (8007.0, 0.00535), (4430.0, 0.00536), (179534.0, 0.00535), (5968.0, 0.00535), (6994.0, 0.00536), (3413.0, 0.00536), (24405.0, 0.00536), (8539.0, 0.00534), (2403.0, 0.00535), (7525.0, 0.00535), (8551.0, 0.00536), (9063.0, 0.00535), (12141.0, 0.00536), (12142.0, 0.00535), (18289.0, 0.00535), (184700.0, 0.00536), (4990.0, 0.00533), (148350.0, 0.00535), (254338.0, 0.00535), (2436.0, 0.00535), (180112.0, 0.00535), (12689.0, 0.00535), (100243.0, 0.00536), (13721.0, 0.00534), (64410.0, 0.00535), (150937.0, 0.00535), (8606.0, 0.00535), (62374.0, 0.00536), (23978.0, 0.00535), (6066.0, 0.00535), (12726.0, 0.00536), (7620.0, 0.00536), (114628.0, 0.00535), (25030.0, 0.00535), (186310.0, 0.00537), (10187.0, 0.00535), (185291.0, 0.00536), (26061.0, 0.00535), (20430.0, 0.00535), (1487.0, 0.00535), (5073.0, 0.00535), (12756.0, 0.00535), (7637.0, 0.00535), (28118.0, 0.00535), (6104.0, 0.00535), (138205.0, 0.00535), (29150.0, 0.00536), (66016.0, 0.00536), (160225.0, 0.00535), (241637.0, 0.00579), (166385.0, 0.0465), (2547.0, 0.00535), (8692.0, 0.00535), (9203.0, 0.00536), (143356.0, 0.00536), (4093.0, 0.00535)])\n",
      "2019-09-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1045          0.056289  2019-12-01\n",
      "1      1230          0.045802  2019-12-01\n",
      "2      1602          0.045064  2019-12-01\n",
      "3      1690          0.035741  2019-12-01\n",
      "4      1722          0.032343  2019-12-01\n",
      "..      ...               ...         ...\n",
      "173  245918          0.051146  2019-12-01\n",
      "174  254338          0.037354  2019-12-01\n",
      "175  260774          0.017445  2019-12-01\n",
      "176  260778          0.053016  2019-12-01\n",
      "177  287882          0.022797  2019-12-01\n",
      "\n",
      "[178 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2018-12-03    5439.0      32.66           NaN\n",
      "1     2018-12-04    5439.0      31.44     -0.037355\n",
      "2     2018-12-06    5439.0      29.79     -0.052481\n",
      "3     2018-12-07    5439.0      29.68     -0.003693\n",
      "4     2018-12-10    5439.0      29.28     -0.013477\n",
      "...          ...       ...        ...           ...\n",
      "56133 2019-11-22  260774.0      54.91      0.002373\n",
      "56134 2019-11-25  260774.0      56.12      0.022036\n",
      "56135 2019-11-26  260774.0      57.88      0.031361\n",
      "56136 2019-11-27  260774.0      57.56     -0.005529\n",
      "56137 2019-11-29  260774.0      57.02     -0.009382\n",
      "\n",
      "[56138 rows x 4 columns]\n",
      "cleaned_weights_min:  OrderedDict([(4611.0, 0.00538), (6669.0, 0.00538), (2574.0, 0.00539), (189459.0, 0.00538), (1045.0, 0.00539), (6682.0, 0.00538), (31774.0, 0.00538), (25119.0, 0.00538), (3107.0, 0.00538), (165927.0, 0.00539), (10793.0, 0.00538), (162346.0, 0.00539), (10795.0, 0.00538), (61483.0, 0.00539), (30259.0, 0.00538), (9783.0, 0.00538), (187450.0, 0.00538), (1602.0, 0.00539), (3650.0, 0.00539), (4674.0, 0.00538), (28742.0, 0.00536), (162887.0, 0.00539), (8264.0, 0.00539), (7241.0, 0.00539), (65609.0, 0.00537), (23627.0, 0.00539), (5709.0, 0.00538), (27215.0, 0.00538), (183377.0, 0.00538), (152149.0, 0.00538), (14934.0, 0.00539), (12892.0, 0.00538), (142953.0, 0.00539), (29804.0, 0.00539), (13421.0, 0.00538), (186989.0, 0.00539), (4093.0, 0.00538), (5234.0, 0.00538), (10867.0, 0.00538), (64630.0, 0.00538), (170617.0, 0.00538), (63099.0, 0.00539), (147579.0, 0.00538), (160893.0, 0.00538), (61567.0, 0.00539), (4737.0, 0.00538), (133768.0, 0.00538), (287882.0, 0.00538), (145552.0, 0.00538), (158354.0, 0.00539), (145046.0, 0.00539), (10903.0, 0.00538), (61591.0, 0.00539), (25753.0, 0.00538), (1690.0, 0.00539), (5786.0, 0.00538), (9882.0, 0.00538), (24731.0, 0.00538), (63643.0, 0.00539), (125595.0, 0.00539), (6304.0, 0.00539), (145049.0, 0.00538), (245918.0, 0.00539), (6821.0, 0.00538), (6310.0, 0.00538), (8358.0, 0.00531), (10405.0, 0.00538), (10920.0, 0.00537), (260774.0, 0.00538), (3243.0, 0.00538), (29868.0, 0.00539), (260778.0, 0.00538), (6831.0, 0.00539), (9904.0, 0.00539), (126136.0, 0.00539), (1722.0, 0.00538), (7866.0, 0.00538), (199356.0, 0.00538), (11456.0, 0.00538), (6338.0, 0.00534), (10443.0, 0.00538), (1230.0, 0.00538), (3278.0, 0.00538), (4818.0, 0.00538), (175319.0, 0.00538), (24800.0, 0.00541), (4839.0, 0.00538), (7922.0, 0.0054), (11506.0, 0.00538), (121077.0, 0.00539), (133366.0, 0.00539), (187128.0, 0.00539), (24316.0, 0.00538), (14590.0, 0.00538), (2817.0, 0.00538), (8455.0, 0.00538), (27914.0, 0.00538), (7435.0, 0.00538), (65290.0, 0.00538), (30990.0, 0.00538), (29968.0, 0.00538), (134932.0, 0.00539), (25880.0, 0.00538), (27928.0, 0.00538), (162076.0, 0.00539), (13599.0, 0.00538), (14624.0, 0.00538), (176928.0, 0.00538), (11554.0, 0.00539), (26410.0, 0.00538), (20779.0, 0.00529), (7991.0, 0.00538), (24379.0, 0.00538), (5439.0, 0.00539), (177983.0, 0.00538), (21825.0, 0.00538), (34636.0, 0.00539), (179534.0, 0.00538), (5968.0, 0.00538), (11600.0, 0.00539), (6994.0, 0.00539), (21841.0, 0.00538), (3413.0, 0.00539), (10581.0, 0.00538), (170841.0, 0.00538), (8539.0, 0.00537), (12123.0, 0.00538), (2403.0, 0.00538), (7525.0, 0.00538), (8551.0, 0.00539), (7017.0, 0.0054), (12141.0, 0.00539), (12142.0, 0.00539), (143357.0, 0.00538), (34164.0, 0.00538), (16245.0, 0.00538), (121718.0, 0.00539), (4990.0, 0.00536), (148350.0, 0.00538), (254338.0, 0.00538), (2435.0, 0.00539), (2436.0, 0.00538), (66446.0, 0.00539), (15247.0, 0.00538), (180112.0, 0.00538), (12689.0, 0.00538), (100243.0, 0.00539), (184725.0, 0.00539), (7063.0, 0.00539), (13721.0, 0.00537), (150937.0, 0.00538), (62374.0, 0.00539), (11687.0, 0.00538), (186278.0, 0.00538), (23978.0, 0.00538), (3502.0, 0.0054), (12726.0, 0.00539), (9155.0, 0.00538), (7620.0, 0.00539), (25030.0, 0.00538), (186310.0, 0.0054), (179657.0, 0.00539), (7116.0, 0.00538), (26061.0, 0.00539), (20430.0, 0.00538), (5073.0, 0.00538), (128978.0, 0.00538), (7637.0, 0.00539), (29150.0, 0.00539), (66016.0, 0.00539), (160225.0, 0.00538), (180711.0, 0.00539), (166385.0, 0.04719), (2547.0, 0.00538), (8692.0, 0.00538), (138743.0, 0.00537), (143356.0, 0.00539), (6653.0, 0.00538)])\n",
      "2019-12-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1045          0.048341  2020-03-01\n",
      "1      1230          0.042273  2020-03-01\n",
      "2      1487          0.032363  2020-03-01\n",
      "3      1678         -0.002429  2020-03-01\n",
      "4      1722          0.024032  2020-03-01\n",
      "..      ...               ...         ...\n",
      "172  187450          0.041265  2020-03-01\n",
      "173  253501          0.032238  2020-03-01\n",
      "174  254338          0.074607  2020-03-01\n",
      "175  260774          0.037374  2020-03-01\n",
      "176  287882          0.006630  2020-03-01\n",
      "\n",
      "[177 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2019-03-01    1678.0      33.99           NaN\n",
      "1     2019-03-04    1678.0      33.67     -0.009415\n",
      "2     2019-03-05    1678.0      33.73      0.001782\n",
      "3     2019-03-06    1678.0      32.73     -0.029647\n",
      "4     2019-03-07    1678.0      33.27      0.016499\n",
      "...          ...       ...        ...           ...\n",
      "60680 2020-02-24  260774.0      60.07     -0.042404\n",
      "60681 2020-02-25  260774.0      57.96     -0.035126\n",
      "60682 2020-02-26  260774.0      56.93     -0.017771\n",
      "60683 2020-02-27  260774.0      56.54     -0.006851\n",
      "60684 2020-02-28  260774.0      56.14     -0.007075\n",
      "\n",
      "[60685 rows x 4 columns]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cleaned_weights_min:  OrderedDict([(4611.0, 0.00546), (9225.0, 0.00541), (2574.0, 0.00578), (1045.0, 0.00532), (8215.0, 0.00527), (6682.0, 0.00541), (28192.0, 0.00523), (3107.0, 0.00506), (165927.0, 0.00513), (10793.0, 0.00547), (10795.0, 0.00554), (26156.0, 0.00531), (61483.0, 0.00522), (2101.0, 0.00538), (15417.0, 0.00501), (29241.0, 0.00532), (187450.0, 0.00525), (253501.0, 0.05), (162887.0, 0.00548), (8264.0, 0.0055), (7241.0, 0.00518), (65609.0, 0.00602), (23627.0, 0.00538), (5709.0, 0.00516), (6733.0, 0.00553), (27215.0, 0.00523), (183377.0, 0.00537), (9299.0, 0.00513), (152149.0, 0.00529), (6742.0, 0.00821), (14934.0, 0.00554), (7260.0, 0.00593), (12892.0, 0.00516), (146017.0, 0.00571), (110179.0, 0.00541), (65640.0, 0.00523), (8810.0, 0.00528), (34410.0, 0.00539), (29804.0, 0.00521), (13421.0, 0.00521), (186989.0, 0.0057), (4093.0, 0.00522), (5234.0, 0.00506), (28790.0, 0.00523), (18043.0, 0.00531), (6781.0, 0.00531), (61567.0, 0.00533), (61574.0, 0.00527), (178310.0, 0.00526), (133768.0, 0.00523), (144009.0, 0.0053), (287882.0, 0.00541), (1678.0, 0.00521), (145552.0, 0.00519), (158354.0, 0.0051), (25753.0, 0.00513), (9882.0, 0.00518), (24731.0, 0.00524), (63643.0, 0.00525), (145049.0, 0.00518), (175263.0, 0.00523), (15520.0, 0.00511), (10405.0, 0.0052), (6310.0, 0.00535), (260774.0, 0.0052), (29868.0, 0.0053), (6831.0, 0.00689), (9904.0, 0.00534), (184500.0, 0.00596), (1722.0, 0.00554), (7866.0, 0.00541), (38077.0, 0.0052), (25279.0, 0.00533), (11456.0, 0.00534), (63172.0, 0.00537), (10443.0, 0.00564), (29389.0, 0.00523), (1230.0, 0.00546), (3278.0, 0.00543), (4818.0, 0.00564), (175319.0, 0.00532), (160991.0, 0.00523), (28385.0, 0.00526), (16101.0, 0.0057), (4839.0, 0.00526), (22260.0, 0.00542), (121077.0, 0.00587), (25338.0, 0.00637), (24316.0, 0.00546), (140541.0, 0.00544), (14590.0, 0.00523), (23809.0, 0.00576), (7938.0, 0.00525), (3851.0, 0.00555), (29968.0, 0.00531), (134932.0, 0.00539), (10519.0, 0.00534), (24344.0, 0.0053), (25880.0, 0.00527), (163610.0, 0.0054), (162076.0, 0.00529), (14624.0, 0.00526), (11554.0, 0.00522), (32546.0, 0.00638), (7974.0, 0.00545), (20779.0, 0.00566), (175404.0, 0.00535), (135990.0, 0.0053), (7991.0, 0.00542), (5439.0, 0.00516), (66368.0, 0.0056), (21825.0, 0.00523), (2884.0, 0.00539), (179534.0, 0.00553), (5968.0, 0.00528), (11600.0, 0.00529), (6994.0, 0.00538), (21841.0, 0.00532), (10581.0, 0.00527), (149337.0, 0.00533), (170841.0, 0.00567), (8539.0, 0.00512), (12123.0, 0.00536), (7525.0, 0.00523), (8549.0, 0.00524), (15208.0, 0.00523), (7017.0, 0.00524), (33138.0, 0.00524), (11636.0, 0.0052), (34164.0, 0.00527), (121718.0, 0.00541), (3964.0, 0.00541), (148350.0, 0.00516), (254338.0, 0.00521), (2435.0, 0.0064), (2436.0, 0.00503), (65417.0, 0.00546), (61325.0, 0.00537), (66446.0, 0.0054), (15247.0, 0.00525), (180112.0, 0.00523), (100243.0, 0.00551), (105365.0, 0.00521), (13721.0, 0.00491), (150937.0, 0.00545), (8606.0, 0.00522), (62374.0, 0.00533), (20904.0, 0.00559), (23978.0, 0.00526), (137131.0, 0.00549), (7085.0, 0.00537), (3502.0, 0.0054), (62897.0, 0.00512), (12726.0, 0.0053), (4029.0, 0.00523), (9155.0, 0.00516), (2504.0, 0.00586), (4040.0, 0.00519), (7116.0, 0.00515), (20430.0, 0.00523), (1487.0, 0.00523), (160211.0, 0.00638), (7637.0, 0.00521), (28118.0, 0.00522), (3036.0, 0.00523), (66016.0, 0.00507), (160225.0, 0.0054), (60900.0, 0.00529), (5606.0, 0.00564), (28139.0, 0.00533), (15855.0, 0.00552), (4598.0, 0.00596), (4601.0, 0.00523), (7163.0, 0.00523), (143356.0, 0.00541), (6653.0, 0.00564), (171007.0, 0.00622)])\n",
      "2020-03-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1045          0.084002  2020-06-01\n",
      "1      1230          0.076685  2020-06-01\n",
      "2      1487          0.078873  2020-06-01\n",
      "3      1661          0.008411  2020-06-01\n",
      "4      1722          0.037712  2020-06-01\n",
      "..      ...               ...         ...\n",
      "172  245918          0.072353  2020-06-01\n",
      "173  253501          0.043140  2020-06-01\n",
      "174  254338          0.124009  2020-06-01\n",
      "175  287882          0.011805  2020-06-01\n",
      "176  312009          0.011793  2020-06-01\n",
      "\n",
      "[177 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2019-06-03    1661.0     124.50           NaN\n",
      "1     2019-06-03    1661.0      20.75     -0.833333\n",
      "2     2019-06-04    1661.0     129.00      5.216867\n",
      "3     2019-06-04    1661.0      21.37     -0.834341\n",
      "4     2019-06-05    1661.0     121.50      4.685540\n",
      "...          ...       ...        ...           ...\n",
      "62379 2020-05-22  110179.0      33.71      0.023687\n",
      "62380 2020-05-26  110179.0      35.54      0.054287\n",
      "62381 2020-05-27  110179.0      37.37      0.051491\n",
      "62382 2020-05-28  110179.0      36.76     -0.016323\n",
      "62383 2020-05-29  110179.0      34.95     -0.049238\n",
      "\n",
      "[62384 rows x 4 columns]\n",
      "cleaned_weights_min:  OrderedDict([(4611.0, 0.0054), (2574.0, 0.00541), (1045.0, 0.00541), (8215.0, 0.00542), (14359.0, 0.00542), (6682.0, 0.00541), (31774.0, 0.00541), (4640.0, 0.00541), (18465.0, 0.00541), (28192.0, 0.00541), (28195.0, 0.00542), (165927.0, 0.00538), (10793.0, 0.00542), (10795.0, 0.00541), (26156.0, 0.00541), (61483.0, 0.00541), (30259.0, 0.00542), (61494.0, 0.00541), (29241.0, 0.00542), (253501.0, 0.00563), (4674.0, 0.00541), (7750.0, 0.00541), (8264.0, 0.00541), (7241.0, 0.00541), (23627.0, 0.00542), (6733.0, 0.00542), (183377.0, 0.00541), (14418.0, 0.00541), (9299.0, 0.00541), (152149.0, 0.00541), (6742.0, 0.00545), (7260.0, 0.00541), (12892.0, 0.00541), (146017.0, 0.00541), (110179.0, 0.00544), (65640.0, 0.00541), (8810.0, 0.00541), (34410.0, 0.00542), (29804.0, 0.00541), (186989.0, 0.00541), (5742.0, 0.00541), (5234.0, 0.00543), (177267.0, 0.00542), (18043.0, 0.00542), (6781.0, 0.00542), (1661.0, 0.00541), (4737.0, 0.00541), (6788.0, 0.00541), (29830.0, 0.00541), (61574.0, 0.00541), (133768.0, 0.00541), (178310.0, 0.00541), (287882.0, 0.0054), (158354.0, 0.0054), (145046.0, 0.00541), (61591.0, 0.00541), (24216.0, 0.00541), (25753.0, 0.00541), (9882.0, 0.00541), (24731.0, 0.00541), (63643.0, 0.00541), (145049.0, 0.00541), (245918.0, 0.00541), (3231.0, 0.00541), (15520.0, 0.00541), (28320.0, 0.00541), (32930.0, 0.00541), (175263.0, 0.00542), (6821.0, 0.00541), (10405.0, 0.00542), (29868.0, 0.00541), (6831.0, 0.00541), (22703.0, 0.00541), (1722.0, 0.00541), (165052.0, 0.0054), (38077.0, 0.00542), (11456.0, 0.00541), (25283.0, 0.00542), (14535.0, 0.00542), (312009.0, 0.00541), (10443.0, 0.0054), (1230.0, 0.00541), (3278.0, 0.00541), (4818.0, 0.00542), (16101.0, 0.00542), (4839.0, 0.00542), (13041.0, 0.00541), (22260.0, 0.00541), (9465.0, 0.00541), (25338.0, 0.00541), (24316.0, 0.00541), (14590.0, 0.00541), (2312.0, 0.00541), (3336.0, 0.00541), (65290.0, 0.00541), (3851.0, 0.00541), (30990.0, 0.00541), (134932.0, 0.00542), (3863.0, 0.00541), (10519.0, 0.00541), (25880.0, 0.00541), (162076.0, 0.00541), (14624.0, 0.00541), (176928.0, 0.00542), (3362.0, 0.00541), (135990.0, 0.00542), (7991.0, 0.0054), (24379.0, 0.00541), (177983.0, 0.00541), (66368.0, 0.00542), (21825.0, 0.00541), (2884.0, 0.00542), (32580.0, 0.00541), (5968.0, 0.00541), (21841.0, 0.00541), (6994.0, 0.00541), (162129.0, 0.00542), (3413.0, 0.00542), (10581.0, 0.0054), (170841.0, 0.00541), (8539.0, 0.00542), (8030.0, 0.00542), (8543.0, 0.00542), (15208.0, 0.00541), (11636.0, 0.00541), (16245.0, 0.00541), (34164.0, 0.00541), (121718.0, 0.00541), (4988.0, 0.00541), (3964.0, 0.00541), (148350.0, 0.00542), (35714.0, 0.00541), (254338.0, 0.00541), (2436.0, 0.00541), (8068.0, 0.00541), (10121.0, 0.00541), (61325.0, 0.00541), (15247.0, 0.00542), (13714.0, 0.00546), (7063.0, 0.00541), (150937.0, 0.00541), (8606.0, 0.00541), (62374.0, 0.00541), (5543.0, 0.00541), (20904.0, 0.00541), (186278.0, 0.00541), (23978.0, 0.00542), (29099.0, 0.00541), (198058.0, 0.00541), (7085.0, 0.00541), (62897.0, 0.00541), (12726.0, 0.00541), (30137.0, 0.00541), (5568.0, 0.00541), (6081.0, 0.00557), (2504.0, 0.00541), (4040.0, 0.00541), (3532.0, 0.00541), (7116.0, 0.00539), (1487.0, 0.00541), (5071.0, 0.00541), (3026.0, 0.00543), (7637.0, 0.00541), (28118.0, 0.00541), (8151.0, 0.00541), (3036.0, 0.00541), (7648.0, 0.04674), (66016.0, 0.00541), (5606.0, 0.00541), (28139.0, 0.00542), (15855.0, 0.00543), (104432.0, 0.00542), (2547.0, 0.00541), (4598.0, 0.00542), (4601.0, 0.00541), (143356.0, 0.00541), (4093.0, 0.00541)])\n",
      "2020-06-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1045          0.036589  2020-09-01\n",
      "1      1075          0.021184  2020-09-01\n",
      "2      1230          0.034833  2020-09-01\n",
      "3      1487          0.040449  2020-09-01\n",
      "4      1722          0.034605  2020-09-01\n",
      "..      ...               ...         ...\n",
      "173  186989          0.003334  2020-09-01\n",
      "174  245918          0.053847  2020-09-01\n",
      "175  254338          0.092176  2020-09-01\n",
      "176  260774          0.039212  2020-09-01\n",
      "177  312009          0.004184  2020-09-01\n",
      "\n",
      "[178 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2019-09-03    5439.0      18.76           NaN\n",
      "1     2019-09-04    5439.0      18.76      0.000000\n",
      "2     2019-09-05    5439.0      19.00      0.012793\n",
      "3     2019-09-06    5439.0      19.09      0.004737\n",
      "4     2019-09-09    5439.0      19.95      0.045050\n",
      "...          ...       ...        ...           ...\n",
      "64870 2020-08-25  260774.0      47.39      0.008083\n",
      "64871 2020-08-26  260774.0      46.98     -0.008652\n",
      "64872 2020-08-27  260774.0      47.35      0.007876\n",
      "64873 2020-08-28  260774.0      47.85      0.010560\n",
      "64874 2020-08-31  260774.0      47.03     -0.017137\n",
      "\n",
      "[64875 rows x 4 columns]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cleaned_weights_min:  OrderedDict([(4611.0, 0.00538), (2574.0, 0.00538), (66065.0, 0.00538), (1045.0, 0.00538), (6682.0, 0.00538), (31774.0, 0.00538), (4640.0, 0.00538), (28192.0, 0.00538), (165927.0, 0.00535), (24616.0, 0.00538), (10793.0, 0.00538), (10795.0, 0.00538), (26156.0, 0.00537), (61483.0, 0.00538), (5680.0, 0.00538), (3121.0, 0.00538), (1075.0, 0.00538), (9783.0, 0.00538), (4674.0, 0.00538), (7750.0, 0.00538), (162887.0, 0.00538), (6216.0, 0.00538), (7241.0, 0.00538), (23627.0, 0.00539), (6733.0, 0.00538), (11856.0, 0.00538), (183377.0, 0.00538), (14418.0, 0.00538), (9299.0, 0.00538), (152149.0, 0.00538), (14934.0, 0.00535), (7260.0, 0.00538), (12892.0, 0.00538), (36444.0, 0.00538), (146017.0, 0.00538), (110179.0, 0.00541), (8810.0, 0.00538), (163946.0, 0.0054), (186989.0, 0.00538), (5742.0, 0.00538), (5234.0, 0.00538), (9846.0, 0.00538), (28790.0, 0.00538), (4737.0, 0.00538), (29830.0, 0.00538), (61574.0, 0.00537), (133768.0, 0.00538), (178310.0, 0.00538), (35978.0, 0.00538), (145552.0, 0.00538), (158354.0, 0.00537), (20116.0, 0.00572), (145046.0, 0.00538), (61591.0, 0.00538), (12441.0, 0.00538), (14489.0, 0.00538), (24731.0, 0.00538), (63643.0, 0.00538), (145049.0, 0.00538), (245918.0, 0.00538), (175263.0, 0.00538), (15520.0, 0.00538), (28320.0, 0.00538), (6821.0, 0.00538), (10405.0, 0.00538), (260774.0, 0.00538), (10920.0, 0.00538), (3243.0, 0.00538), (29868.0, 0.00538), (150699.0, 0.00538), (6831.0, 0.00538), (7343.0, 0.00538), (1722.0, 0.00538), (165052.0, 0.00538), (25283.0, 0.00538), (14535.0, 0.00539), (312009.0, 0.00538), (10443.0, 0.00537), (29389.0, 0.00554), (1230.0, 0.00538), (3278.0, 0.00538), (4818.0, 0.00538), (175319.0, 0.00538), (2269.0, 0.00538), (24800.0, 0.00538), (4839.0, 0.00539), (6375.0, 0.00538), (13041.0, 0.00538), (11506.0, 0.00538), (22260.0, 0.00538), (9465.0, 0.00538), (25338.0, 0.00538), (24316.0, 0.00538), (140541.0, 0.00538), (14590.0, 0.00538), (23809.0, 0.0054), (155394.0, 0.00538), (65290.0, 0.00538), (3851.0, 0.00538), (3863.0, 0.00538), (10519.0, 0.00538), (11032.0, 0.00538), (24344.0, 0.00538), (162076.0, 0.00538), (176928.0, 0.00538), (145701.0, 0.00538), (20779.0, 0.00537), (61739.0, 0.00538), (135990.0, 0.00538), (7991.0, 0.00538), (24379.0, 0.00537), (5439.0, 0.00538), (21825.0, 0.00538), (2884.0, 0.00538), (32580.0, 0.00538), (8007.0, 0.00538), (178507.0, 0.00538), (179534.0, 0.00538), (5968.0, 0.00538), (11600.0, 0.00538), (6994.0, 0.00538), (8530.0, 0.00537), (21841.0, 0.00538), (3413.0, 0.00538), (10581.0, 0.00538), (170841.0, 0.00538), (8539.0, 0.00539), (8543.0, 0.00538), (35168.0, 0.00538), (29028.0, 0.00538), (8549.0, 0.00538), (15208.0, 0.00538), (16245.0, 0.00538), (121718.0, 0.00537), (4988.0, 0.00538), (148349.0, 0.00539), (148350.0, 0.00539), (184700.0, 0.00538), (254338.0, 0.00538), (2435.0, 0.00539), (2436.0, 0.00538), (8068.0, 0.00538), (10121.0, 0.00538), (61325.0, 0.00538), (15247.0, 0.00538), (180112.0, 0.00538), (13714.0, 0.00545), (7063.0, 0.00538), (13721.0, 0.00538), (150937.0, 0.00538), (64925.0, 0.00538), (8606.0, 0.00538), (4517.0, 0.00538), (62374.0, 0.00538), (5543.0, 0.00538), (186278.0, 0.00538), (23978.0, 0.00538), (137131.0, 0.00538), (62897.0, 0.00538), (12726.0, 0.00538), (2504.0, 0.00538), (4040.0, 0.00538), (7116.0, 0.00535), (26061.0, 0.00539), (1487.0, 0.00538), (7637.0, 0.00538), (28118.0, 0.00538), (8151.0, 0.00538), (3036.0, 0.00538), (138205.0, 0.00538), (7648.0, 0.04736), (66016.0, 0.00538), (160225.0, 0.00538), (180711.0, 0.00538), (28139.0, 0.00538), (2547.0, 0.00538), (4598.0, 0.00538), (171007.0, 0.00538)])\n",
      "2020-09-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1209          0.021135  2020-12-01\n",
      "1      1380         -0.013999  2020-12-01\n",
      "2      1913          0.026441  2020-12-01\n",
      "3      2019          0.047975  2020-12-01\n",
      "4      2136          0.030411  2020-12-01\n",
      "..      ...               ...         ...\n",
      "198  260774          0.033072  2020-12-01\n",
      "199  287882         -0.013644  2020-12-01\n",
      "200  294524          0.025693  2020-12-01\n",
      "201  312009         -0.007539  2020-12-01\n",
      "202  316056          0.029590  2020-12-01\n",
      "\n",
      "[203 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2019-12-02    1380.0      61.19           NaN\n",
      "1     2019-12-03    1380.0      59.79     -0.022880\n",
      "2     2019-12-04    1380.0      61.22      0.023917\n",
      "3     2019-12-05    1380.0      60.95     -0.004410\n",
      "4     2019-12-06    1380.0      62.26      0.021493\n",
      "...          ...       ...        ...           ...\n",
      "65375 2020-11-23  260774.0      59.78      0.025386\n",
      "65376 2020-11-24  260774.0      61.46      0.028103\n",
      "65377 2020-11-25  260774.0      61.26     -0.003254\n",
      "65378 2020-11-27  260774.0      61.13     -0.002122\n",
      "65379 2020-11-30  260774.0      61.14      0.000164\n",
      "\n",
      "[65380 rows x 4 columns]\n",
      "cleaned_weights_min:  OrderedDict([(4108.0, 0.00493), (6669.0, 0.00493), (2574.0, 0.00493), (66065.0, 0.00493), (6682.0, 0.00493), (25119.0, 0.00493), (4640.0, 0.00493), (3619.0, 0.00493), (11300.0, 0.00493), (20004.0, 0.00493), (10793.0, 0.00493), (61483.0, 0.00493), (3121.0, 0.00493), (9778.0, 0.00493), (9783.0, 0.00493), (7750.0, 0.00493), (7241.0, 0.00493), (160329.0, 0.00493), (5709.0, 0.00493), (11856.0, 0.00493), (183377.0, 0.00493), (152149.0, 0.00493), (6742.0, 0.00493), (14934.0, 0.00493), (2136.0, 0.00493), (4699.0, 0.00493), (7260.0, 0.00493), (12892.0, 0.00493), (36444.0, 0.00493), (110179.0, 0.00493), (12389.0, 0.00493), (65640.0, 0.00493), (142953.0, 0.00493), (13421.0, 0.00493), (186989.0, 0.00493), (6774.0, 0.00493), (8823.0, 0.00493), (64630.0, 0.00493), (170617.0, 0.00493), (18043.0, 0.00493), (147579.0, 0.00493), (294524.0, 0.00493), (4737.0, 0.00493), (24197.0, 0.00493), (61574.0, 0.00493), (133768.0, 0.00493), (35978.0, 0.00493), (287882.0, 0.00493), (145552.0, 0.00493), (61591.0, 0.00493), (316056.0, 0.00493), (14489.0, 0.00493), (3226.0, 0.00493), (24731.0, 0.00493), (63643.0, 0.00493), (3231.0, 0.00493), (6304.0, 0.00493), (28320.0, 0.00493), (157855.0, 0.00493), (175263.0, 0.00493), (6821.0, 0.00493), (260774.0, 0.00493), (10920.0, 0.00493), (3243.0, 0.00493), (2220.0, 0.00493), (9899.0, 0.00493), (12459.0, 0.00493), (29868.0, 0.00493), (150699.0, 0.00493), (180405.0, 0.00493), (126136.0, 0.00493), (1209.0, 0.00493), (7866.0, 0.00493), (199356.0, 0.00493), (37054.0, 0.00493), (11456.0, 0.00493), (6338.0, 0.00493), (14535.0, 0.00493), (312009.0, 0.00493), (28877.0, 0.00493), (3278.0, 0.00493), (4818.0, 0.00493), (175319.0, 0.00493), (24800.0, 0.00493), (4839.0, 0.00493), (6375.0, 0.00493), (13041.0, 0.00493), (11506.0, 0.00493), (22260.0, 0.00493), (133366.0, 0.00493), (9465.0, 0.00493), (25340.0, 0.00493), (140541.0, 0.00493), (14590.0, 0.00493), (23809.0, 0.00493), (155394.0, 0.00493), (65290.0, 0.00493), (7435.0, 0.00493), (8463.0, 0.00493), (134932.0, 0.00493), (3863.0, 0.00493), (11032.0, 0.00493), (24344.0, 0.00493), (25880.0, 0.00493), (4383.0, 0.00493), (10016.0, 0.00493), (14624.0, 0.00493), (11554.0, 0.00493), (32546.0, 0.00493), (176928.0, 0.00493), (20779.0, 0.00493), (61739.0, 0.00493), (7985.0, 0.00493), (7991.0, 0.00493), (24379.0, 0.00493), (5439.0, 0.00493), (177983.0, 0.00493), (21825.0, 0.00493), (2884.0, 0.00493), (32580.0, 0.00493), (178507.0, 0.00493), (34636.0, 0.00493), (179534.0, 0.00493), (11600.0, 0.00493), (16721.0, 0.00493), (21841.0, 0.00493), (9555.0, 0.00493), (36691.0, 0.00493), (3413.0, 0.00493), (10581.0, 0.00493), (170841.0, 0.00493), (8539.0, 0.00493), (114524.0, 0.00493), (8030.0, 0.00493), (36191.0, 0.00493), (1380.0, 0.00493), (6502.0, 0.00493), (9063.0, 0.00493), (36203.0, 0.00493), (12142.0, 0.00493), (143357.0, 0.00493), (165746.0, 0.00493), (11636.0, 0.00493), (16245.0, 0.00493), (121718.0, 0.00493), (1913.0, 0.00493), (4988.0, 0.00493), (148349.0, 0.00493), (148350.0, 0.00493), (184700.0, 0.00493), (254338.0, 0.00493), (2436.0, 0.00493), (10121.0, 0.00493), (9611.0, 0.00493), (3980.0, 0.00493), (61325.0, 0.00493), (66446.0, 0.00493), (15247.0, 0.00493), (12689.0, 0.00493), (13714.0, 0.00493), (139665.0, 0.00493), (24468.0, 0.00493), (7063.0, 0.00493), (13721.0, 0.00493), (150937.0, 0.00493), (64925.0, 0.00493), (8099.0, 0.00493), (4517.0, 0.00493), (186278.0, 0.00493), (11687.0, 0.00493), (7085.0, 0.00493), (3502.0, 0.00493), (62897.0, 0.00493), (5046.0, 0.00493), (12726.0, 0.00493), (18872.0, 0.00493), (186310.0, 0.00493), (164296.0, 0.00493), (26061.0, 0.00493), (5071.0, 0.00493), (5073.0, 0.00493), (17874.0, 0.00493), (128978.0, 0.00493), (11220.0, 0.00493), (7637.0, 0.00493), (28118.0, 0.00493), (8151.0, 0.00493), (3036.0, 0.00493), (5597.0, 0.00493), (138205.0, 0.00493), (7648.0, 0.00493), (66016.0, 0.00493), (4066.0, 0.00493), (2019.0, 0.00493), (60900.0, 0.00493), (160225.0, 0.00493), (180711.0, 0.00493), (2547.0, 0.00493), (4598.0, 0.00493), (6136.0, 0.00493), (3580.0, 0.00493), (4093.0, 0.00493), (171007.0, 0.00493)])\n",
      "2020-12-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1690          0.036048  2021-03-01\n",
      "1      1722          0.025952  2021-03-01\n",
      "2      1878          0.036808  2021-03-01\n",
      "3      1913          0.030108  2021-03-01\n",
      "4      2184          0.034166  2021-03-01\n",
      "..      ...               ...         ...\n",
      "172  241637          0.022685  2021-03-01\n",
      "173  260774          0.031973  2021-03-01\n",
      "174  287882         -0.005180  2021-03-01\n",
      "175  294524          0.028310  2021-03-01\n",
      "176  312009         -0.014550  2021-03-01\n",
      "\n",
      "[177 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2020-03-02    5439.0      17.22           NaN\n",
      "1     2020-03-03    5439.0      15.95     -0.073751\n",
      "2     2020-03-04    5439.0      15.39     -0.035110\n",
      "3     2020-03-05    5439.0      14.74     -0.042235\n",
      "4     2020-03-06    5439.0      13.07     -0.113297\n",
      "...          ...       ...        ...           ...\n",
      "62155 2021-02-22  260774.0      75.25      0.034506\n",
      "62156 2021-02-23  260774.0      77.88      0.034950\n",
      "62157 2021-02-24  260774.0      77.18     -0.008988\n",
      "62158 2021-02-25  260774.0      74.57     -0.033817\n",
      "62159 2021-02-26  260774.0      75.77      0.016092\n",
      "\n",
      "[62160 rows x 4 columns]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cleaned_weights_min:  OrderedDict([(4108.0, 0.00565), (6669.0, 0.00565), (2574.0, 0.00565), (66065.0, 0.00565), (6682.0, 0.00565), (25119.0, 0.00565), (4640.0, 0.00565), (28192.0, 0.00565), (3619.0, 0.00565), (11300.0, 0.00565), (165927.0, 0.00565), (24616.0, 0.00565), (10793.0, 0.00565), (61483.0, 0.00565), (9778.0, 0.00565), (15417.0, 0.00565), (187450.0, 0.00565), (20548.0, 0.00565), (7750.0, 0.00565), (28742.0, 0.00565), (6216.0, 0.00565), (160329.0, 0.00565), (6733.0, 0.00565), (183377.0, 0.00565), (152149.0, 0.00565), (6742.0, 0.00565), (14934.0, 0.00565), (7260.0, 0.00565), (12892.0, 0.00565), (36444.0, 0.00565), (146017.0, 0.00565), (36967.0, 0.00565), (142953.0, 0.00565), (8810.0, 0.00565), (29804.0, 0.00565), (11376.0, 0.00565), (5234.0, 0.00565), (10867.0, 0.00565), (6774.0, 0.00565), (8823.0, 0.00565), (9846.0, 0.00565), (18043.0, 0.00565), (294524.0, 0.00565), (61567.0, 0.00565), (4737.0, 0.00565), (24197.0, 0.00565), (178310.0, 0.00565), (2184.0, 0.00565), (133768.0, 0.00565), (287882.0, 0.00565), (34443.0, 0.00565), (145552.0, 0.00565), (158354.0, 0.00565), (145046.0, 0.00565), (61591.0, 0.00565), (12441.0, 0.00565), (1690.0, 0.00565), (14489.0, 0.00565), (24731.0, 0.00565), (25753.0, 0.00565), (175263.0, 0.00565), (6304.0, 0.00565), (28320.0, 0.00565), (6821.0, 0.00565), (6310.0, 0.00565), (260774.0, 0.00565), (3243.0, 0.00565), (2220.0, 0.00565), (12459.0, 0.00565), (29868.0, 0.00565), (184500.0, 0.00565), (1722.0, 0.00565), (165052.0, 0.00565), (37054.0, 0.00565), (6338.0, 0.00565), (63172.0, 0.00565), (14535.0, 0.00565), (312009.0, 0.00565), (160479.0, 0.00565), (24800.0, 0.00565), (3813.0, 0.00565), (13041.0, 0.00565), (22260.0, 0.00565), (121077.0, 0.00565), (133366.0, 0.00565), (9465.0, 0.00565), (25340.0, 0.00565), (140541.0, 0.00565), (14590.0, 0.00565), (23809.0, 0.00565), (155394.0, 0.00565), (165123.0, 0.00565), (65290.0, 0.00565), (7435.0, 0.00565), (3863.0, 0.00565), (10519.0, 0.00565), (11032.0, 0.00565), (25880.0, 0.00565), (30490.0, 0.00565), (11550.0, 0.00565), (10016.0, 0.00565), (176928.0, 0.00565), (7970.0, 0.00565), (11554.0, 0.00565), (20779.0, 0.00565), (5439.0, 0.00565), (11584.0, 0.00565), (21825.0, 0.00565), (2884.0, 0.00565), (32580.0, 0.00565), (178507.0, 0.00565), (179534.0, 0.00565), (11600.0, 0.00565), (8530.0, 0.00565), (9555.0, 0.00565), (36691.0, 0.00565), (1878.0, 0.00565), (149337.0, 0.00565), (8539.0, 0.00565), (114524.0, 0.00565), (8030.0, 0.00565), (8543.0, 0.00565), (36191.0, 0.00565), (31587.0, 0.00565), (7525.0, 0.00565), (15208.0, 0.00565), (32106.0, 0.00565), (36203.0, 0.00565), (3439.0, 0.00565), (33138.0, 0.00565), (1913.0, 0.00565), (184700.0, 0.00565), (8068.0, 0.00565), (10121.0, 0.00565), (9611.0, 0.00565), (61325.0, 0.00565), (66446.0, 0.00565), (15247.0, 0.00565), (180112.0, 0.00565), (12689.0, 0.00565), (139665.0, 0.00565), (24468.0, 0.00565), (7063.0, 0.00565), (13721.0, 0.00565), (150937.0, 0.00565), (62374.0, 0.00565), (186278.0, 0.00565), (3502.0, 0.00565), (62897.0, 0.00565), (6066.0, 0.00565), (5046.0, 0.00565), (12726.0, 0.00565), (31673.0, 0.00565), (186310.0, 0.00565), (29127.0, 0.00565), (4040.0, 0.00565), (164296.0, 0.00565), (179657.0, 0.00565), (5071.0, 0.00565), (5073.0, 0.00565), (128978.0, 0.00565), (12756.0, 0.00565), (8151.0, 0.00565), (138205.0, 0.00565), (26590.0, 0.00565), (66016.0, 0.00565), (160225.0, 0.00565), (60900.0, 0.00565), (241637.0, 0.00565), (180711.0, 0.00565), (2547.0, 0.00565), (9203.0, 0.00565), (4598.0, 0.00565), (4601.0, 0.00565), (7163.0, 0.00565), (143357.0, 0.00565), (171007.0, 0.00565)])\n",
      "2021-03-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1161          0.025872  2021-06-01\n",
      "1      1209          0.009008  2021-06-01\n",
      "2      1327          0.025872  2021-06-01\n",
      "3      1487          0.020719  2021-06-01\n",
      "4      1632          0.025872  2021-06-01\n",
      "..      ...               ...         ...\n",
      "244  189459          0.020983  2021-06-01\n",
      "245  245918          0.020425  2021-06-01\n",
      "246  260774          0.020714  2021-06-01\n",
      "247  287882         -0.026324  2021-06-01\n",
      "248  316056          0.012529  2021-06-01\n",
      "\n",
      "[249 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2020-06-01    1678.0      11.73           NaN\n",
      "1     2020-06-02    1678.0      12.23      0.042626\n",
      "2     2020-06-03    1678.0      12.53      0.024530\n",
      "3     2020-06-04    1678.0      13.00      0.037510\n",
      "4     2020-06-05    1678.0      16.07      0.236154\n",
      "...          ...       ...        ...           ...\n",
      "76720 2021-05-24  260774.0      88.76      0.018123\n",
      "76721 2021-05-25  260774.0      88.12     -0.007210\n",
      "76722 2021-05-26  260774.0      88.22      0.001135\n",
      "76723 2021-05-27  260774.0      87.59     -0.007141\n",
      "76724 2021-05-28  260774.0      87.78      0.002169\n",
      "\n",
      "[76725 rows x 4 columns]\n",
      "cleaned_weights_min:  OrderedDict([(11264.0, 0.00402), (117768.0, 0.00402), (100873.0, 0.00402), (6669.0, 0.00402), (2574.0, 0.00402), (178704.0, 0.00402), (189459.0, 0.00402), (28180.0, 0.00402), (6682.0, 0.00402), (175955.0, 0.00402), (13341.0, 0.00402), (25119.0, 0.00402), (3619.0, 0.00402), (11300.0, 0.00402), (10789.0, 0.00402), (11811.0, 0.00402), (28195.0, 0.00402), (24616.0, 0.00402), (121382.0, 0.00402), (61483.0, 0.00402), (26156.0, 0.00402), (9778.0, 0.00402), (2101.0, 0.00402), (15417.0, 0.00402), (29241.0, 0.00402), (187450.0, 0.00402), (3650.0, 0.00402), (7750.0, 0.00402), (7241.0, 0.00402), (5709.0, 0.00402), (23119.0, 0.00402), (8272.0, 0.00402), (183377.0, 0.00402), (9299.0, 0.00402), (152149.0, 0.00402), (14934.0, 0.00402), (141913.0, 0.00402), (12892.0, 0.00402), (36444.0, 0.00402), (1632.0, 0.00402), (146017.0, 0.00402), (12389.0, 0.00402), (2663.0, 0.00402), (36967.0, 0.00402), (63080.0, 0.00402), (165993.0, 0.00402), (36860.0, 0.00402), (13421.0, 0.00402), (5742.0, 0.00402), (177267.0, 0.00402), (6774.0, 0.00402), (9846.0, 0.00402), (160888.0, 0.00402), (18043.0, 0.00402), (147579.0, 0.00402), (6781.0, 0.00402), (178310.0, 0.00402), (11399.0, 0.00402), (2184.0, 0.00402), (1161.0, 0.00402), (5256.0, 0.00402), (27786.0, 0.00402), (34443.0, 0.00402), (34955.0, 0.00402), (1678.0, 0.00402), (35978.0, 0.00402), (144009.0, 0.00402), (145552.0, 0.00402), (158354.0, 0.00402), (287882.0, 0.00402), (20116.0, 0.00402), (3221.0, 0.00402), (145046.0, 0.00402), (61591.0, 0.00402), (316056.0, 0.00402), (12441.0, 0.00402), (1690.0, 0.00402), (14489.0, 0.00402), (25753.0, 0.00402), (63643.0, 0.00402), (125595.0, 0.00402), (157855.0, 0.00402), (6304.0, 0.00402), (28320.0, 0.00402), (175263.0, 0.00402), (245918.0, 0.00402), (6821.0, 0.00402), (6310.0, 0.00402), (64166.0, 0.00402), (1704.0, 0.00402), (10920.0, 0.00402), (260774.0, 0.00402), (12459.0, 0.00402), (2220.0, 0.00402), (29868.0, 0.00402), (150699.0, 0.00402), (7343.0, 0.00402), (184500.0, 0.00402), (1209.0, 0.00402), (1722.0, 0.00402), (7866.0, 0.00402), (165052.0, 0.00402), (38077.0, 0.00402), (37054.0, 0.00402), (25279.0, 0.00402), (6338.0, 0.00402), (63172.0, 0.00402), (10443.0, 0.00402), (30923.0, 0.00402), (29901.0, 0.00402), (8402.0, 0.00402), (10453.0, 0.00402), (37594.0, 0.00402), (2269.0, 0.00402), (160479.0, 0.00402), (24800.0, 0.00402), (28385.0, 0.00402), (160991.0, 0.00402), (3813.0, 0.00402), (4839.0, 0.00402), (61676.0, 0.00402), (11506.0, 0.00402), (121077.0, 0.00402), (133366.0, 0.00402), (111864.0, 0.00402), (12540.0, 0.00402), (25340.0, 0.00402), (14590.0, 0.00402), (126721.0, 0.00402), (7938.0, 0.00402), (10499.0, 0.00402), (155394.0, 0.00402), (165123.0, 0.00402), (3336.0, 0.00402), (20232.0, 0.00402), (7435.0, 0.00402), (18699.0, 0.00402), (20748.0, 0.00402), (32530.0, 0.00402), (134932.0, 0.00402), (3863.0, 0.00402), (11032.0, 0.00402), (24856.0, 0.00402), (25880.0, 0.00402), (27928.0, 0.00402), (30490.0, 0.00402), (163610.0, 0.00402), (22815.0, 0.00402), (10016.0, 0.00402), (176928.0, 0.00402), (3362.0, 0.00402), (32546.0, 0.00402), (7974.0, 0.00402), (20779.0, 0.00402), (175404.0, 0.00402), (1327.0, 0.00402), (7985.0, 0.00402), (187697.0, 0.00402), (22325.0, 0.00402), (27965.0, 0.00402), (28477.0, 0.00402), (177983.0, 0.00402), (66368.0, 0.00402), (3905.0, 0.00402), (178507.0, 0.00402), (34636.0, 0.00402), (179534.0, 0.00402), (11600.0, 0.00402), (21841.0, 0.00402), (8530.0, 0.00402), (36691.0, 0.00402), (113490.0, 0.00402), (3413.0, 0.00402), (1878.0, 0.00402), (10581.0, 0.00402), (24405.0, 0.00402), (64853.0, 0.00402), (149337.0, 0.00402), (12635.0, 0.00402), (114524.0, 0.00402), (24925.0, 0.00402), (8030.0, 0.00402), (8543.0, 0.00402), (1891.0, 0.00402), (64356.0, 0.00402), (7525.0, 0.00402), (15208.0, 0.00402), (36203.0, 0.00402), (4973.0, 0.00402), (12141.0, 0.00402), (3439.0, 0.00402), (12142.0, 0.00402), (11636.0, 0.00402), (121718.0, 0.00402), (6008.0, 0.00402), (1913.0, 0.00402), (184700.0, 0.00402), (61325.0, 0.00402), (4494.0, 0.00402), (24975.0, 0.00402), (12689.0, 0.00402), (139665.0, 0.00402), (184725.0, 0.00402), (4503.0, 0.00402), (7063.0, 0.00402), (7065.0, 0.00402), (13721.0, 0.00402), (64410.0, 0.00402), (150937.0, 0.00402), (7585.0, 0.00402), (8099.0, 0.00402), (6565.0, 0.00402), (14256.0, 0.00402), (62897.0, 0.00402), (6066.0, 0.00402), (12726.0, 0.00402), (31673.0, 0.00402), (5568.0, 0.00402), (6081.0, 0.00402), (186310.0, 0.00402), (29127.0, 0.00402), (2504.0, 0.00402), (179657.0, 0.00402), (14282.0, 0.00402), (3532.0, 0.00402), (26061.0, 0.00402), (162254.0, 0.00402), (1487.0, 0.00402), (5071.0, 0.00402), (5073.0, 0.00402), (128978.0, 0.00402), (8151.0, 0.00402), (5597.0, 0.00402), (7648.0, 0.00402), (160225.0, 0.00402), (60900.0, 0.00402), (5606.0, 0.00402), (180711.0, 0.00402), (28139.0, 0.00402), (15855.0, 0.00402), (166385.0, 0.00402), (4598.0, 0.00402), (138743.0, 0.00402), (4601.0, 0.00402), (23546.0, 0.00402), (7163.0, 0.00402), (3580.0, 0.00402), (143357.0, 0.00402), (171007.0, 0.00402)])\n",
      "2021-06-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1161          0.033455  2021-09-01\n",
      "1      1209          0.017214  2021-09-01\n",
      "2      1230          0.019485  2021-09-01\n",
      "3      1327          0.033455  2021-09-01\n",
      "4      1487          0.034467  2021-09-01\n",
      "..      ...               ...         ...\n",
      "245  187697          0.033455  2021-09-01\n",
      "246  188255          0.019775  2021-09-01\n",
      "247  260774          0.023074  2021-09-01\n",
      "248  287882         -0.003328  2021-09-01\n",
      "249  316056          0.020795  2021-09-01\n",
      "\n",
      "[250 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2020-09-01    1678.0      14.94           NaN\n",
      "1     2020-09-02    1678.0      14.42     -0.034806\n",
      "2     2020-09-03    1678.0      14.39     -0.002080\n",
      "3     2020-09-04    1678.0      14.60      0.014593\n",
      "4     2020-09-08    1678.0      13.04     -0.106849\n",
      "...          ...       ...        ...           ...\n",
      "77229 2021-08-25  260774.0      94.49      0.017225\n",
      "77230 2021-08-26  260774.0      93.64     -0.008996\n",
      "77231 2021-08-27  260774.0      95.62      0.021145\n",
      "77232 2021-08-30  260774.0      96.02      0.004183\n",
      "77233 2021-08-31  260774.0      96.30      0.002916\n",
      "\n",
      "[77234 rows x 4 columns]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cleaned_weights_min:  OrderedDict([(4611.0, 0.004), (117768.0, 0.004), (100873.0, 0.004), (2574.0, 0.004), (175955.0, 0.004), (31774.0, 0.004), (25119.0, 0.004), (3107.0, 0.004), (11811.0, 0.004), (10789.0, 0.004), (28195.0, 0.004), (121382.0, 0.004), (24616.0, 0.004), (61483.0, 0.004), (26156.0, 0.004), (9778.0, 0.004), (30259.0, 0.004), (2101.0, 0.004), (15414.0, 0.004), (19000.0, 0.004), (15417.0, 0.004), (29241.0, 0.004), (187450.0, 0.004), (3650.0, 0.004), (20548.0, 0.004), (7750.0, 0.004), (3144.0, 0.004), (8264.0, 0.004), (65609.0, 0.004), (23627.0, 0.004), (5709.0, 0.004), (23119.0, 0.004), (183377.0, 0.004), (9299.0, 0.004), (152149.0, 0.004), (6742.0, 0.004), (141913.0, 0.004), (12892.0, 0.004), (36444.0, 0.004), (1632.0, 0.004), (146017.0, 0.004), (12389.0, 0.004), (63080.0, 0.004), (142953.0, 0.004), (163946.0, 0.004), (165993.0, 0.004), (13421.0, 0.004), (186989.0, 0.004), (11376.0, 0.004), (14960.0, 0.004), (177267.0, 0.004), (9846.0, 0.004), (28790.0, 0.004), (64630.0, 0.004), (160888.0, 0.004), (18043.0, 0.004), (3708.0, 0.004), (147579.0, 0.004), (61567.0, 0.004), (61574.0, 0.004), (11399.0, 0.004), (133768.0, 0.004), (1161.0, 0.004), (178310.0, 0.004), (34443.0, 0.004), (34955.0, 0.004), (287882.0, 0.004), (1678.0, 0.004), (158354.0, 0.004), (20116.0, 0.004), (145046.0, 0.004), (61591.0, 0.004), (316056.0, 0.004), (12441.0, 0.004), (1690.0, 0.004), (14489.0, 0.004), (25753.0, 0.004), (63643.0, 0.004), (125595.0, 0.004), (157855.0, 0.004), (6304.0, 0.004), (28320.0, 0.004), (175263.0, 0.004), (6821.0, 0.004), (260774.0, 0.004), (1704.0, 0.004), (10920.0, 0.004), (3243.0, 0.004), (2220.0, 0.004), (12459.0, 0.004), (29868.0, 0.004), (6831.0, 0.004), (7343.0, 0.004), (184500.0, 0.004), (1209.0, 0.004), (1722.0, 0.004), (7866.0, 0.004), (165052.0, 0.004), (38077.0, 0.004), (37054.0, 0.004), (25279.0, 0.004), (11456.0, 0.004), (6338.0, 0.004), (7875.0, 0.004), (63172.0, 0.004), (23238.0, 0.004), (1230.0, 0.004), (3278.0, 0.004), (4818.0, 0.004), (8402.0, 0.004), (10453.0, 0.004), (175319.0, 0.004), (37594.0, 0.004), (37596.0, 0.004), (24800.0, 0.004), (28385.0, 0.004), (4839.0, 0.004), (6375.0, 0.004), (61676.0, 0.004), (121077.0, 0.004), (133366.0, 0.004), (111864.0, 0.004), (9465.0, 0.004), (13561.0, 0.004), (12540.0, 0.004), (24316.0, 0.004), (14590.0, 0.004), (140541.0, 0.004), (23809.0, 0.004), (7938.0, 0.004), (10499.0, 0.004), (126721.0, 0.004), (2312.0, 0.004), (3336.0, 0.004), (20232.0, 0.004), (18699.0, 0.004), (20748.0, 0.004), (65290.0, 0.004), (32530.0, 0.004), (134932.0, 0.004), (24344.0, 0.004), (25880.0, 0.004), (27928.0, 0.004), (30490.0, 0.004), (162076.0, 0.004), (163610.0, 0.004), (22815.0, 0.004), (176928.0, 0.004), (11554.0, 0.004), (32546.0, 0.004), (7974.0, 0.004), (20779.0, 0.004), (175404.0, 0.004), (1327.0, 0.004), (187697.0, 0.004), (22325.0, 0.004), (135990.0, 0.004), (7991.0, 0.004), (27965.0, 0.004), (177983.0, 0.004), (66368.0, 0.004), (178507.0, 0.004), (179534.0, 0.004), (11600.0, 0.004), (21841.0, 0.004), (6994.0, 0.004), (8530.0, 0.004), (36691.0, 0.004), (10581.0, 0.004), (1878.0, 0.004), (24405.0, 0.004), (64853.0, 0.004), (149337.0, 0.004), (170841.0, 0.004), (8539.0, 0.004), (12635.0, 0.004), (24925.0, 0.004), (8030.0, 0.004), (188255.0, 0.004), (1891.0, 0.004), (64356.0, 0.004), (7525.0, 0.004), (8549.0, 0.004), (15208.0, 0.004), (36203.0, 0.004), (143356.0, 0.004), (4973.0, 0.004), (12141.0, 0.004), (3439.0, 0.004), (12142.0, 0.004), (33138.0, 0.004), (11636.0, 0.004), (121718.0, 0.004), (6008.0, 0.004), (184700.0, 0.004), (148349.0, 0.004), (4990.0, 0.004), (148350.0, 0.004), (2435.0, 0.004), (9611.0, 0.004), (61325.0, 0.004), (15247.0, 0.004), (24975.0, 0.004), (139665.0, 0.004), (180112.0, 0.004), (184725.0, 0.004), (4503.0, 0.004), (7063.0, 0.004), (7065.0, 0.004), (13721.0, 0.004), (150937.0, 0.004), (7585.0, 0.004), (6565.0, 0.004), (38821.0, 0.004), (62374.0, 0.004), (186278.0, 0.004), (14256.0, 0.004), (62897.0, 0.004), (6066.0, 0.004), (12726.0, 0.004), (29127.0, 0.004), (2504.0, 0.004), (179657.0, 0.004), (14282.0, 0.004), (3532.0, 0.004), (26061.0, 0.004), (162254.0, 0.004), (1487.0, 0.004), (5073.0, 0.004), (128978.0, 0.004), (8151.0, 0.004), (11228.0, 0.004), (29150.0, 0.004), (7648.0, 0.004), (160225.0, 0.004), (60900.0, 0.004), (5606.0, 0.004), (180711.0, 0.004), (28139.0, 0.004), (15855.0, 0.004), (166385.0, 0.004), (7154.0, 0.004), (4598.0, 0.004), (138743.0, 0.004), (4601.0, 0.004), (23546.0, 0.004), (7163.0, 0.004), (36860.0, 0.004), (143357.0, 0.004), (171007.0, 0.004)])\n",
      "2021-09-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1045          0.024735  2021-12-01\n",
      "1      1075          0.019112  2021-12-01\n",
      "2      1161          0.031775  2021-12-01\n",
      "3      1209          0.017508  2021-12-01\n",
      "4      1230          0.035464  2021-12-01\n",
      "..      ...               ...         ...\n",
      "243  187697          0.031775  2021-12-01\n",
      "244  245918          0.035400  2021-12-01\n",
      "245  260774          0.019030  2021-12-01\n",
      "246  287882         -0.021431  2021-12-01\n",
      "247  316056          0.022383  2021-12-01\n",
      "\n",
      "[248 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2020-12-01    2991.0      87.45           NaN\n",
      "1     2020-12-02    2991.0      89.87      0.027673\n",
      "2     2020-12-03    2991.0      89.80     -0.000779\n",
      "3     2020-12-04    2991.0      93.28      0.038753\n",
      "4     2020-12-07    2991.0      90.76     -0.027015\n",
      "...          ...       ...        ...           ...\n",
      "78352 2021-11-23  260774.0     103.84      0.048889\n",
      "78353 2021-11-24  260774.0     104.24      0.003852\n",
      "78354 2021-11-26  260774.0      98.09     -0.058998\n",
      "78355 2021-11-29  260774.0      97.96     -0.001325\n",
      "78356 2021-11-30  260774.0      95.57     -0.024398\n",
      "\n",
      "[78357 rows x 4 columns]\n",
      "cleaned_weights_min:  OrderedDict([(117768.0, 0.00387), (100873.0, 0.00388), (2574.0, 0.00387), (28180.0, 0.00385), (1045.0, 0.00387), (175955.0, 0.00405), (31774.0, 0.00387), (25119.0, 0.00386), (3107.0, 0.00387), (3619.0, 0.00387), (10789.0, 0.0039), (11811.0, 0.00387), (28195.0, 0.00387), (24616.0, 0.00389), (29733.0, 0.00387), (121382.0, 0.00388), (61483.0, 0.00388), (26156.0, 0.00383), (9778.0, 0.00387), (1075.0, 0.00388), (15414.0, 0.00388), (19000.0, 0.00388), (15417.0, 0.00388), (29241.0, 0.00387), (187450.0, 0.00388), (7750.0, 0.00387), (3144.0, 0.00387), (65609.0, 0.00388), (160329.0, 0.00387), (5709.0, 0.00387), (23119.0, 0.00387), (183377.0, 0.00388), (14418.0, 0.00389), (9299.0, 0.00387), (152149.0, 0.00387), (6742.0, 0.00388), (14934.0, 0.00387), (141913.0, 0.00388), (12892.0, 0.00388), (36444.0, 0.00391), (1632.0, 0.00389), (12389.0, 0.00387), (63080.0, 0.00388), (142953.0, 0.00387), (165993.0, 0.00387), (29804.0, 0.00388), (13421.0, 0.00387), (186989.0, 0.00387), (11376.0, 0.00388), (177267.0, 0.00386), (28790.0, 0.00387), (160888.0, 0.00387), (170617.0, 0.00372), (147579.0, 0.00387), (3708.0, 0.00387), (61574.0, 0.00387), (11399.0, 0.00388), (5256.0, 0.00393), (1161.0, 0.00389), (144009.0, 0.00386), (34955.0, 0.00386), (178310.0, 0.00388), (287882.0, 0.00388), (145552.0, 0.00387), (158354.0, 0.00388), (20116.0, 0.00386), (3221.0, 0.00385), (61591.0, 0.00388), (316056.0, 0.00387), (12441.0, 0.00399), (1690.0, 0.00386), (9882.0, 0.00387), (14489.0, 0.00386), (39067.0, 0.00388), (63643.0, 0.00387), (125595.0, 0.00388), (6304.0, 0.00387), (28320.0, 0.00388), (157855.0, 0.00387), (175263.0, 0.00387), (245918.0, 0.00387), (10405.0, 0.00388), (260774.0, 0.00388), (1704.0, 0.00387), (10920.0, 0.00388), (2220.0, 0.00459), (29868.0, 0.00387), (6831.0, 0.00387), (7343.0, 0.00392), (184500.0, 0.00389), (180405.0, 0.00388), (1209.0, 0.00387), (1722.0, 0.00387), (13498.0, 0.00386), (165052.0, 0.00391), (38077.0, 0.00387), (25279.0, 0.00387), (6338.0, 0.00388), (63172.0, 0.00382), (1230.0, 0.00387), (3278.0, 0.00389), (164046.0, 0.00387), (4818.0, 0.00404), (8402.0, 0.00386), (10453.0, 0.00386), (175319.0, 0.00387), (37594.0, 0.00388), (37596.0, 0.00388), (160991.0, 0.00387), (24800.0, 0.00387), (28385.0, 0.00387), (4839.0, 0.00387), (6375.0, 0.00388), (61676.0, 0.00387), (121077.0, 0.00389), (133366.0, 0.00387), (111864.0, 0.0039), (9465.0, 0.00388), (13561.0, 0.00387), (12540.0, 0.00388), (23809.0, 0.00393), (7938.0, 0.00387), (10499.0, 0.00387), (126721.0, 0.00389), (2312.0, 0.00388), (3336.0, 0.00389), (20232.0, 0.00388), (3851.0, 0.00387), (7435.0, 0.00386), (18699.0, 0.00387), (20748.0, 0.00388), (32530.0, 0.00388), (134932.0, 0.00387), (3863.0, 0.00386), (24344.0, 0.00387), (25880.0, 0.00386), (27928.0, 0.00387), (30490.0, 0.00387), (162076.0, 0.00388), (8479.0, 0.00404), (22815.0, 0.00387), (176928.0, 0.00386), (11554.0, 0.00389), (32546.0, 0.00389), (7974.0, 0.00388), (7977.0, 0.00389), (20779.0, 0.00388), (175404.0, 0.00387), (1327.0, 0.00388), (187697.0, 0.00387), (22325.0, 0.00391), (135990.0, 0.00387), (7991.0, 0.00387), (27965.0, 0.00387), (177983.0, 0.00386), (66368.0, 0.00387), (2884.0, 0.00388), (178507.0, 0.00387), (179534.0, 0.00387), (5968.0, 0.00387), (6994.0, 0.00387), (8530.0, 0.00387), (113490.0, 0.00395), (3413.0, 0.00388), (1878.0, 0.00388), (10581.0, 0.00387), (24405.0, 0.00389), (64853.0, 0.00391), (25434.0, 0.00388), (12635.0, 0.00389), (149337.0, 0.00387), (24925.0, 0.00388), (170841.0, 0.00387), (1891.0, 0.00384), (64356.0, 0.00387), (7525.0, 0.00387), (6502.0, 0.00389), (15208.0, 0.00387), (36203.0, 0.00387), (143356.0, 0.00385), (4973.0, 0.0039), (12141.0, 0.00385), (12142.0, 0.00387), (37233.0, 0.00385), (33138.0, 0.00387), (143357.0, 0.00388), (11636.0, 0.00387), (121718.0, 0.00386), (6008.0, 0.00386), (1913.0, 0.00387), (184700.0, 0.00389), (148350.0, 0.00388), (2435.0, 0.00389), (8068.0, 0.00387), (65417.0, 0.00387), (61325.0, 0.00387), (15247.0, 0.00386), (24975.0, 0.00387), (139665.0, 0.00394), (180112.0, 0.00387), (100243.0, 0.00387), (184725.0, 0.00389), (4503.0, 0.00394), (7063.0, 0.00387), (7065.0, 0.00388), (11672.0, 0.00387), (13721.0, 0.00387), (150937.0, 0.00387), (7585.0, 0.00399), (6565.0, 0.00388), (38821.0, 0.00387), (20904.0, 0.00388), (2991.0, 0.00387), (62897.0, 0.00387), (6066.0, 0.0039), (12726.0, 0.00387), (1988.0, 0.00387), (29127.0, 0.00388), (2504.0, 0.00385), (164296.0, 0.00387), (14282.0, 0.00388), (179657.0, 0.00388), (3532.0, 0.00387), (5073.0, 0.00385), (128978.0, 0.00388), (11220.0, 0.00387), (28118.0, 0.00389), (6104.0, 0.00386), (5597.0, 0.00388), (29150.0, 0.00387), (138205.0, 0.00386), (7648.0, 0.00387), (160225.0, 0.00391), (5606.0, 0.00388), (180711.0, 0.00387), (28139.0, 0.00387), (15855.0, 0.00388), (104432.0, 0.00388), (166385.0, 0.04159), (7154.0, 0.00384), (4598.0, 0.00387), (138743.0, 0.00388), (4601.0, 0.00387), (23546.0, 0.00378), (7163.0, 0.00386), (36860.0, 0.00387), (4093.0, 0.00387), (171007.0, 0.0039)])\n",
      "2021-12-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1045          0.032440  2022-03-01\n",
      "1      1075          0.015347  2022-03-01\n",
      "2      1078          0.034532  2022-03-01\n",
      "3      1440          0.014555  2022-03-01\n",
      "4      1487          0.039672  2022-03-01\n",
      "..      ...               ...         ...\n",
      "232  199356          0.044334  2022-03-01\n",
      "233  260774          0.026490  2022-03-01\n",
      "234  287882         -0.021236  2022-03-01\n",
      "235  312009         -0.023727  2022-03-01\n",
      "236  316056          0.024902  2022-03-01\n",
      "\n",
      "[237 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2021-03-01    1661.0     117.86           NaN\n",
      "1     2021-03-01    1661.0      16.69     -0.858391\n",
      "2     2021-03-02    1661.0     105.06      5.294787\n",
      "3     2021-03-02    1661.0      15.13     -0.855987\n",
      "4     2021-03-03    1661.0     109.15      6.214144\n",
      "...          ...       ...        ...           ...\n",
      "78366 2022-02-22  260774.0      99.17     -0.005216\n",
      "78367 2022-02-23  260774.0      96.05     -0.031461\n",
      "78368 2022-02-24  260774.0      93.84     -0.023009\n",
      "78369 2022-02-25  260774.0      98.63      0.051044\n",
      "78370 2022-02-28  260774.0      96.85     -0.018047\n",
      "\n",
      "[78371 rows x 4 columns]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cleaned_weights_min:  OrderedDict([(11264.0, 0.00406), (7171.0, 0.00406), (17928.0, 0.00406), (100873.0, 0.00407), (117768.0, 0.00405), (2574.0, 0.00407), (1045.0, 0.00407), (36885.0, 0.00407), (136725.0, 0.00413), (31774.0, 0.00406), (28191.0, 0.00407), (3107.0, 0.00406), (2086.0, 0.00408), (121382.0, 0.00407), (24616.0, 0.00409), (10793.0, 0.00407), (61483.0, 0.00408), (36911.0, 0.00407), (4145.0, 0.00407), (9778.0, 0.00407), (1075.0, 0.00407), (12850.0, 0.00406), (2101.0, 0.00407), (1078.0, 0.00404), (15414.0, 0.00407), (19000.0, 0.00407), (15417.0, 0.00406), (61494.0, 0.00407), (161844.0, 0.00407), (7228.0, 0.00407), (187450.0, 0.00406), (2111.0, 0.00406), (1602.0, 0.00406), (7750.0, 0.00406), (162887.0, 0.00407), (141384.0, 0.00407), (7241.0, 0.00409), (6730.0, 0.00407), (23627.0, 0.00405), (22604.0, 0.00407), (5709.0, 0.00406), (6733.0, 0.00415), (23119.0, 0.00404), (65609.0, 0.00407), (160329.0, 0.00407), (183377.0, 0.00406), (9299.0, 0.00406), (152149.0, 0.00407), (6742.0, 0.00407), (14934.0, 0.00406), (7257.0, 0.00407), (126554.0, 0.00405), (12892.0, 0.00407), (36444.0, 0.00409), (110179.0, 0.00407), (142953.0, 0.00406), (34410.0, 0.00407), (163946.0, 0.00407), (29804.0, 0.00407), (13421.0, 0.00409), (186989.0, 0.00406), (11376.0, 0.00407), (14960.0, 0.00407), (9846.0, 0.00406), (28790.0, 0.00407), (64630.0, 0.00431), (160888.0, 0.00406), (6266.0, 0.00409), (18043.0, 0.00406), (3708.0, 0.00406), (1661.0, 0.00407), (147579.0, 0.00406), (170617.0, 0.00389), (24197.0, 0.00416), (61574.0, 0.00407), (287882.0, 0.00407), (1678.0, 0.00407), (31887.0, 0.0041), (145552.0, 0.00406), (158354.0, 0.00407), (20116.0, 0.00405), (145046.0, 0.00407), (3735.0, 0.00406), (10903.0, 0.00407), (25753.0, 0.00407), (316056.0, 0.00406), (24731.0, 0.00498), (39067.0, 0.00407), (63643.0, 0.00407), (6304.0, 0.00406), (10405.0, 0.00407), (64166.0, 0.00408), (10407.0, 0.00406), (10920.0, 0.00407), (260774.0, 0.00407), (3243.0, 0.00406), (2220.0, 0.00431), (29868.0, 0.00406), (6831.0, 0.00406), (144559.0, 0.00409), (184500.0, 0.00408), (13498.0, 0.00406), (199356.0, 0.00407), (28349.0, 0.00406), (37054.0, 0.00407), (2751.0, 0.00406), (25279.0, 0.00406), (6338.0, 0.00407), (63172.0, 0.00402), (7366.0, 0.00407), (23238.0, 0.00407), (39624.0, 0.00407), (312009.0, 0.00407), (29901.0, 0.00406), (3278.0, 0.00406), (24782.0, 0.00407), (4818.0, 0.00423), (37594.0, 0.00407), (4321.0, 0.00407), (25313.0, 0.00407), (16101.0, 0.00407), (4839.0, 0.00407), (65772.0, 0.00408), (22260.0, 0.00407), (133366.0, 0.00407), (13561.0, 0.00406), (25338.0, 0.00407), (12540.0, 0.00406), (10499.0, 0.00406), (20228.0, 0.00407), (23812.0, 0.00407), (165123.0, 0.00405), (2312.0, 0.00407), (20232.0, 0.00407), (27914.0, 0.00405), (7435.0, 0.00405), (65290.0, 0.00406), (3863.0, 0.00405), (11032.0, 0.00406), (24344.0, 0.00406), (24856.0, 0.00408), (25880.0, 0.00406), (30490.0, 0.00406), (162076.0, 0.00407), (176928.0, 0.00405), (3362.0, 0.00406), (10530.0, 0.00417), (7974.0, 0.00407), (12589.0, 0.00406), (187697.0, 0.00417), (13619.0, 0.00407), (22325.0, 0.00408), (7991.0, 0.00407), (3897.0, 0.00406), (5439.0, 0.00407), (3905.0, 0.00409), (35649.0, 0.00406), (149318.0, 0.00399), (178507.0, 0.00407), (179534.0, 0.00406), (5968.0, 0.00407), (21841.0, 0.00407), (6994.0, 0.00406), (8530.0, 0.00406), (9555.0, 0.00406), (24405.0, 0.00407), (1878.0, 0.00408), (113490.0, 0.00414), (126296.0, 0.00407), (149337.0, 0.00407), (170841.0, 0.0041), (8543.0, 0.00407), (2403.0, 0.00406), (6502.0, 0.00408), (15208.0, 0.00406), (143356.0, 0.00404), (12141.0, 0.00405), (37233.0, 0.00404), (33138.0, 0.00406), (34164.0, 0.00406), (1913.0, 0.00406), (184700.0, 0.00409), (148349.0, 0.0041), (148350.0, 0.00408), (35714.0, 0.00407), (2435.0, 0.00407), (8068.0, 0.00406), (10115.0, 0.00408), (13700.0, 0.00406), (9611.0, 0.00408), (61325.0, 0.00407), (15247.0, 0.00406), (180112.0, 0.00406), (139665.0, 0.00409), (100243.0, 0.00406), (24468.0, 0.00407), (184725.0, 0.00408), (4503.0, 0.00412), (7063.0, 0.00406), (7065.0, 0.00408), (13721.0, 0.00407), (4510.0, 0.00407), (1440.0, 0.00406), (6565.0, 0.00407), (38821.0, 0.00402), (20904.0, 0.00406), (137131.0, 0.00407), (3504.0, 0.00407), (62897.0, 0.00405), (12726.0, 0.00407), (30137.0, 0.00406), (31673.0, 0.00407), (183366.0, 0.00406), (186310.0, 0.00407), (29127.0, 0.00407), (7116.0, 0.00406), (26061.0, 0.00407), (1487.0, 0.00406), (5073.0, 0.00404), (128978.0, 0.00406), (11220.0, 0.00407), (7637.0, 0.00407), (28118.0, 0.00407), (6104.0, 0.00406), (138205.0, 0.00406), (29150.0, 0.00406), (160225.0, 0.0041), (180711.0, 0.00406), (104432.0, 0.00407), (166385.0, 0.03833), (2547.0, 0.00403), (4598.0, 0.00406), (4601.0, 0.00406), (7163.0, 0.00406), (36860.0, 0.00407), (4093.0, 0.00406), (171007.0, 0.00409)])\n",
      "2022-03-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1045          0.043538  2022-06-01\n",
      "1      1078          0.032767  2022-06-01\n",
      "2      1209          0.018073  2022-06-01\n",
      "3      1602          0.032767  2022-06-01\n",
      "4      1661         -0.019572  2022-06-01\n",
      "..      ...               ...         ...\n",
      "230  186989          0.003898  2022-06-01\n",
      "231  187450          0.040441  2022-06-01\n",
      "232  189459          0.026717  2022-06-01\n",
      "233  199356          0.064424  2022-06-01\n",
      "234  260774          0.020728  2022-06-01\n",
      "\n",
      "[235 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2021-06-01    1661.0     108.15           NaN\n",
      "1     2021-06-02    1661.0     124.45      0.150717\n",
      "2     2021-06-03    1661.0     118.09     -0.051105\n",
      "3     2021-06-04    1661.0     121.13      0.025743\n",
      "4     2021-06-07    1661.0     114.42     -0.055395\n",
      "...          ...       ...        ...           ...\n",
      "75825 2022-05-24  260774.0      78.82     -0.018064\n",
      "75826 2022-05-25  260774.0      79.28      0.005836\n",
      "75827 2022-05-26  260774.0      81.93      0.033426\n",
      "75828 2022-05-27  260774.0      84.05      0.025876\n",
      "75829 2022-05-31  260774.0      82.84     -0.014396\n",
      "\n",
      "[75830 rows x 4 columns]\n",
      "cleaned_weights_min:  OrderedDict([(7171.0, 0.00409), (17928.0, 0.0041), (100873.0, 0.0041), (2574.0, 0.0041), (178704.0, 0.00412), (119314.0, 0.00413), (189459.0, 0.00411), (1045.0, 0.0041), (36885.0, 0.00411), (136725.0, 0.00411), (6682.0, 0.00411), (31774.0, 0.0041), (2086.0, 0.00411), (121382.0, 0.0041), (165927.0, 0.00411), (24617.0, 0.00409), (10795.0, 0.00412), (61483.0, 0.00412), (36911.0, 0.0041), (4145.0, 0.00411), (9778.0, 0.00411), (12850.0, 0.0041), (161844.0, 0.00411), (1078.0, 0.00408), (15414.0, 0.00411), (19000.0, 0.00411), (15417.0, 0.0041), (61494.0, 0.0041), (187450.0, 0.00411), (7228.0, 0.0041), (2111.0, 0.0041), (1602.0, 0.00411), (7750.0, 0.0041), (162887.0, 0.00411), (141384.0, 0.00411), (7241.0, 0.00413), (6730.0, 0.00411), (23627.0, 0.00409), (22604.0, 0.00411), (5709.0, 0.0041), (149070.0, 0.0041), (183377.0, 0.0041), (152149.0, 0.00411), (6742.0, 0.0041), (7257.0, 0.0041), (126554.0, 0.0041), (12892.0, 0.00411), (36444.0, 0.00411), (34410.0, 0.0041), (29804.0, 0.0041), (186989.0, 0.0041), (11376.0, 0.00412), (14960.0, 0.00413), (5234.0, 0.0041), (9846.0, 0.00409), (28790.0, 0.0041), (6266.0, 0.00413), (147579.0, 0.0041), (3708.0, 0.0041), (1661.0, 0.0041), (61567.0, 0.0041), (24197.0, 0.00419), (61574.0, 0.0041), (1678.0, 0.00411), (31887.0, 0.00414), (145552.0, 0.0041), (158354.0, 0.00411), (20116.0, 0.00409), (3221.0, 0.00409), (145046.0, 0.0041), (3735.0, 0.0041), (10903.0, 0.00412), (12441.0, 0.00421), (1690.0, 0.0041), (9882.0, 0.0041), (25753.0, 0.0041), (61591.0, 0.0041), (63643.0, 0.0041), (145049.0, 0.00411), (6304.0, 0.00413), (32930.0, 0.0041), (10405.0, 0.00411), (64166.0, 0.00411), (10407.0, 0.00414), (1704.0, 0.0041), (10920.0, 0.00411), (260774.0, 0.00411), (3243.0, 0.0041), (2220.0, 0.00452), (29868.0, 0.0041), (144559.0, 0.00413), (184500.0, 0.00412), (1209.0, 0.0041), (13498.0, 0.00817), (199356.0, 0.00411), (37054.0, 0.00411), (2751.0, 0.00411), (11456.0, 0.0041), (25279.0, 0.0041), (7366.0, 0.00411), (23238.0, 0.0041), (39624.0, 0.0041), (29901.0, 0.0041), (24782.0, 0.00411), (164046.0, 0.0041), (4818.0, 0.00436), (8402.0, 0.0041), (37594.0, 0.00411), (160991.0, 0.0041), (24800.0, 0.0041), (4321.0, 0.00411), (25313.0, 0.00411), (177376.0, 0.0041), (16101.0, 0.0041), (4839.0, 0.0041), (65772.0, 0.00411), (34034.0, 0.0041), (22260.0, 0.0041), (121077.0, 0.00416), (133366.0, 0.00411), (13561.0, 0.00411), (25338.0, 0.00411), (12540.0, 0.0041), (24316.0, 0.00419), (64768.0, 0.00415), (1794.0, 0.00411), (7938.0, 0.00413), (20228.0, 0.00411), (23812.0, 0.00411), (2312.0, 0.00411), (20232.0, 0.0041), (27914.0, 0.00411), (7435.0, 0.00408), (65290.0, 0.0041), (134932.0, 0.0041), (11032.0, 0.0041), (24344.0, 0.0041), (24856.0, 0.00412), (25880.0, 0.00411), (27928.0, 0.00409), (30490.0, 0.0041), (162076.0, 0.0041), (8479.0, 0.00419), (163610.0, 0.00408), (176928.0, 0.00409), (3362.0, 0.00411), (10530.0, 0.0042), (11554.0, 0.00412), (32546.0, 0.00413), (7974.0, 0.00411), (12589.0, 0.0041), (13619.0, 0.00412), (135990.0, 0.0041), (7991.0, 0.0041), (3897.0, 0.0041), (27965.0, 0.0041), (5439.0, 0.00411), (35649.0, 0.0041), (149318.0, 0.00403), (178507.0, 0.00412), (179534.0, 0.0041), (21841.0, 0.00411), (8530.0, 0.00411), (10581.0, 0.0041), (126296.0, 0.00409), (149337.0, 0.0041), (170841.0, 0.00415), (8543.0, 0.00411), (36191.0, 0.0041), (2403.0, 0.0041), (15208.0, 0.0041), (12141.0, 0.00408), (3439.0, 0.00411), (18289.0, 0.0041), (33138.0, 0.0041), (165746.0, 0.0041), (34164.0, 0.00411), (1913.0, 0.00411), (184700.0, 0.00414), (148349.0, 0.00413), (148350.0, 0.00412), (35714.0, 0.00412), (2435.0, 0.0041), (10115.0, 0.00412), (13700.0, 0.0041), (61325.0, 0.00411), (15247.0, 0.00412), (180112.0, 0.0041), (139665.0, 0.00411), (100243.0, 0.0041), (24468.0, 0.00416), (184725.0, 0.00412), (7063.0, 0.0041), (7065.0, 0.00412), (13721.0, 0.00412), (4510.0, 0.00411), (8099.0, 0.00411), (15267.0, 0.00411), (6565.0, 0.00411), (38821.0, 0.00411), (20904.0, 0.00411), (137131.0, 0.00411), (26028.0, 0.00414), (28590.0, 0.0041), (3504.0, 0.0041), (62897.0, 0.00411), (12726.0, 0.0041), (18872.0, 0.00413), (30137.0, 0.0041), (31673.0, 0.00411), (5568.0, 0.0041), (1988.0, 0.0041), (186310.0, 0.00411), (29127.0, 0.0041), (164296.0, 0.00411), (179657.0, 0.00411), (7116.0, 0.0041), (26061.0, 0.0041), (5073.0, 0.00408), (128978.0, 0.0041), (7637.0, 0.0041), (28118.0, 0.00411), (6104.0, 0.00411), (138205.0, 0.0041), (160225.0, 0.00411), (180711.0, 0.0041), (104432.0, 0.00411), (166385.0, 0.03371), (2547.0, 0.00409), (8692.0, 0.00412), (138743.0, 0.00416), (4601.0, 0.0041), (7163.0, 0.0041), (36860.0, 0.0041), (171007.0, 0.00413)])\n",
      "2022-06-01 : Done\n",
      "      gvkey  predicted_return  trade_date\n",
      "0      1045          0.059392  2022-09-01\n",
      "1      1075          0.012211  2022-09-01\n",
      "2      1078          0.033595  2022-09-01\n",
      "3      1161          0.036295  2022-09-01\n",
      "4      1230          0.052560  2022-09-01\n",
      "..      ...               ...         ...\n",
      "298  187697          0.036295  2022-09-01\n",
      "299  241637          0.017479  2022-09-01\n",
      "300  260774          0.027837  2022-09-01\n",
      "301  287882         -0.000764  2022-09-01\n",
      "302  316056          0.034261  2022-09-01\n",
      "\n",
      "[303 rows x 3 columns]\n",
      "        datadate     gvkey  adj_price  daily_return\n",
      "0     2021-09-01    1661.0      83.68           NaN\n",
      "1     2021-09-01    1661.0       5.80     -0.930688\n",
      "2     2021-09-02    1661.0      85.13     13.677586\n",
      "3     2021-09-02    1661.0       6.05     -0.928932\n",
      "4     2021-09-03    1661.0      83.33     12.773554\n",
      "...          ...       ...        ...           ...\n",
      "98493 2022-08-25  260774.0      83.45      0.025310\n",
      "98494 2022-08-26  260774.0      80.43     -0.036189\n",
      "98495 2022-08-29  260774.0      79.43     -0.012433\n",
      "98496 2022-08-30  260774.0      78.81     -0.007806\n",
      "98497 2022-08-31  260774.0      78.96      0.001903\n",
      "\n",
      "[98498 rows x 4 columns]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cleaned_weights_min:  OrderedDict([(7171.0, 0.00292), (17928.0, 0.0032), (100873.0, 0.00289), (117768.0, 0.00274), (28180.0, 0.00249), (1045.0, 0.00299), (36885.0, 0.00317), (136725.0, 0.00299), (6682.0, 0.00294), (31774.0, 0.00296), (11811.0, 0.00283), (28195.0, 0.00302), (10789.0, 0.00301), (2086.0, 0.00303), (29733.0, 0.00292), (24616.0, 0.00312), (10793.0, 0.003), (121382.0, 0.00304), (10795.0, 0.00315), (26156.0, 0.00298), (61483.0, 0.00311), (165927.0, 0.00307), (36911.0, 0.00286), (4145.0, 0.00309), (9778.0, 0.00288), (1075.0, 0.00291), (1078.0, 0.00307), (9783.0, 0.00294), (15414.0, 0.00301), (15417.0, 0.00296), (19000.0, 0.00312), (29241.0, 0.00306), (7228.0, 0.00307), (61494.0, 0.00296), (187450.0, 0.003), (2111.0, 0.00296), (1602.0, 0.00305), (7750.0, 0.00287), (162887.0, 0.00282), (8264.0, 0.00296), (7241.0, 0.00298), (6730.0, 0.00357), (23627.0, 0.003), (22604.0, 0.00317), (5709.0, 0.0029), (6733.0, 0.00295), (23119.0, 0.00322), (141384.0, 0.00322), (160329.0, 0.00322), (14418.0, 0.00285), (183377.0, 0.00304), (152149.0, 0.00291), (6742.0, 0.00303), (7257.0, 0.00297), (126554.0, 0.00293), (141913.0, 0.00306), (12892.0, 0.00286), (36444.0, 0.00308), (1632.0, 0.00308), (63080.0, 0.0028), (165993.0, 0.00296), (34410.0, 0.00296), (163946.0, 0.00302), (29804.0, 0.00297), (13421.0, 0.00394), (186989.0, 0.00297), (11376.0, 0.00323), (14960.0, 0.00311), (5234.0, 0.00301), (177267.0, 0.00351), (28790.0, 0.00297), (160888.0, 0.00291), (170617.0, 0.00272), (6266.0, 0.00293), (3708.0, 0.00295), (1661.0, 0.00296), (126721.0, 0.0056), (61567.0, 0.00305), (24197.0, 0.00302), (61574.0, 0.00295), (11399.0, 0.00303), (178310.0, 0.00297), (1161.0, 0.00293), (287882.0, 0.00295), (34955.0, 0.00314), (1678.0, 0.0031), (31887.0, 0.0035), (145552.0, 0.00309), (158354.0, 0.00289), (20116.0, 0.00302), (145046.0, 0.00286), (3735.0, 0.00296), (10903.0, 0.00328), (12441.0, 0.00294), (1690.0, 0.00299), (9882.0, 0.00311), (14489.0, 0.00301), (61591.0, 0.00304), (63643.0, 0.00301), (125595.0, 0.00289), (6304.0, 0.00373), (28320.0, 0.00295), (32930.0, 0.003), (157855.0, 0.00286), (175263.0, 0.00303), (6821.0, 0.00293), (10405.0, 0.00296), (10407.0, 0.00425), (1704.0, 0.00295), (64166.0, 0.00313), (260774.0, 0.00298), (3243.0, 0.00296), (2220.0, 0.00705), (29868.0, 0.00297), (7343.0, 0.00299), (9904.0, 0.00299), (144559.0, 0.00279), (1722.0, 0.00297), (13498.0, 0.05), (165052.0, 0.00299), (2751.0, 0.00329), (11456.0, 0.00306), (25279.0, 0.00296), (6338.0, 0.00299), (39624.0, 0.00296), (10443.0, 0.00312), (30923.0, 0.00297), (29901.0, 0.00294), (1230.0, 0.00305), (24782.0, 0.00293), (164046.0, 0.00294), (4818.0, 0.01339), (8402.0, 0.00295), (10453.0, 0.00306), (175319.0, 0.00305), (37594.0, 0.00297), (171007.0, 0.00306), (37596.0, 0.0032), (24800.0, 0.00303), (25313.0, 0.00286), (28385.0, 0.00311), (16101.0, 0.00292), (4839.0, 0.00305), (61676.0, 0.00291), (65772.0, 0.00522), (179437.0, 0.00299), (13041.0, 0.00296), (22260.0, 0.00303), (121077.0, 0.00316), (133366.0, 0.00292), (316056.0, 0.00288), (111864.0, 0.00313), (13561.0, 0.00306), (25338.0, 0.003), (12540.0, 0.00297), (140541.0, 0.00288), (14590.0, 0.00296), (23809.0, 0.00305), (1794.0, 0.00286), (7938.0, 0.00345), (10499.0, 0.00301), (20228.0, 0.00299), (23812.0, 0.00301), (8455.0, 0.00292), (2312.0, 0.00309), (3336.0, 0.00318), (20232.0, 0.00286), (18699.0, 0.00298), (20748.0, 0.00305), (27914.0, 0.003), (30990.0, 0.00296), (65290.0, 0.00296), (32530.0, 0.00287), (134932.0, 0.00296), (3863.0, 0.00296), (11032.0, 0.00345), (24344.0, 0.00297), (24856.0, 0.00298), (25880.0, 0.00306), (27928.0, 0.00342), (30490.0, 0.00299), (162076.0, 0.00299), (22815.0, 0.00311), (176928.0, 0.00351), (10530.0, 0.00299), (11554.0, 0.003), (32546.0, 0.00315), (7974.0, 0.00313), (20779.0, 0.00294), (175404.0, 0.00301), (12589.0, 0.00315), (1327.0, 0.00314), (187697.0, 0.00393), (10035.0, 0.00296), (13619.0, 0.00325), (64821.0, 0.00311), (135990.0, 0.00301), (7991.0, 0.00302), (27965.0, 0.00299), (177983.0, 0.00301), (66368.0, 0.00301), (21825.0, 0.00296), (35649.0, 0.00299), (149318.0, 0.00294), (178507.0, 0.00298), (179534.0, 0.00293), (21841.0, 0.00293), (6994.0, 0.00297), (8530.0, 0.003), (113490.0, 0.00294), (24405.0, 0.00343), (1878.0, 0.00337), (64853.0, 0.00311), (126296.0, 0.00266), (149337.0, 0.00274), (170841.0, 0.00385), (12635.0, 0.00282), (175955.0, 0.00313), (24925.0, 0.00319), (8030.0, 0.00298), (8543.0, 0.00313), (36191.0, 0.00301), (1891.0, 0.00289), (2403.0, 0.00295), (64356.0, 0.00299), (6502.0, 0.00271), (15208.0, 0.00296), (36203.0, 0.00303), (12141.0, 0.00311), (12142.0, 0.00295), (33138.0, 0.00296), (11636.0, 0.00286), (34164.0, 0.00297), (121718.0, 0.00296), (6008.0, 0.00298), (184700.0, 0.00342), (148349.0, 0.00315), (148350.0, 0.00305), (35714.0, 0.00319), (10115.0, 0.00319), (10121.0, 0.00296), (61325.0, 0.00307), (4494.0, 0.00279), (15247.0, 0.00339), (24975.0, 0.00306), (139665.0, 0.00309), (13714.0, 0.00295), (30098.0, 0.00299), (24468.0, 0.0037), (180112.0, 0.00296), (184725.0, 0.00313), (7063.0, 0.003), (7065.0, 0.00314), (13721.0, 0.0033), (150937.0, 0.00292), (7585.0, 0.00339), (15267.0, 0.00306), (6565.0, 0.00288), (38821.0, 0.00301), (20904.0, 0.0032), (23978.0, 0.00303), (137131.0, 0.00306), (3504.0, 0.00314), (62897.0, 0.00285), (6066.0, 0.00235), (12726.0, 0.0029), (18872.0, 0.00325), (30137.0, 0.00295), (31673.0, 0.00301), (183366.0, 0.00299), (29127.0, 0.00302), (2504.0, 0.0029), (164296.0, 0.00305), (14282.0, 0.00305), (179657.0, 0.00295), (3532.0, 0.00285), (20430.0, 0.00296), (5073.0, 0.00295), (128978.0, 0.00298), (11220.0, 0.00297), (7637.0, 0.00291), (12756.0, 0.00308), (28118.0, 0.00304), (138205.0, 0.00292), (39391.0, 0.003), (7648.0, 0.00757), (66016.0, 0.00314), (160225.0, 0.00294), (60900.0, 0.00307), (241637.0, 0.0106), (5606.0, 0.00307), (180711.0, 0.00296), (28139.0, 0.00293), (15855.0, 0.00311), (104432.0, 0.00292), (166385.0, 0.00582), (2547.0, 0.00332), (4601.0, 0.00296), (23546.0, 0.00295), (3580.0, 0.00298), (143357.0, 0.00295), (4094.0, 0.00298), (39935.0, 0.00296)])\n",
      "2022-09-01 : Done\n"
     ]
    }
   ],
   "source": [
    "# took under 5 minutes to run\n",
    "from pypfopt import objective_functions\n",
    "stocks_weight_table = pd.DataFrame([])\n",
    "\n",
    "for i in range(len(trade_date)):\n",
    "    # get selected stocks information\n",
    "    p1_alldata=(all_stocks_info[trade_date[i]])\n",
    "    # sort it by tic\n",
    "    p1_alldata=p1_alldata.sort_values('gvkey')\n",
    "    p1_alldata = p1_alldata.reset_index()\n",
    "    del p1_alldata['index']\n",
    "    \n",
    "    print(p1_alldata)\n",
    "    # get selected stocks tic\n",
    "    p1_stock = p1_alldata.gvkey\n",
    "    \n",
    "    # get predicted return from selected stocks\n",
    "    p1_predicted_return=p1_alldata.pivot_table(index = 'trade_date',columns = 'gvkey', values = 'predicted_return')\n",
    "    # use the predicted returns as the Expected returns to feed into the portfolio object\n",
    "    \n",
    "\n",
    "    # get the 1-year historical return\n",
    "    p1_return_table=all_return_table[trade_date[i]]\n",
    "    p1_return_table_pivot=p1_return_table.pivot_table(index = 'datadate',columns = 'gvkey', values = 'daily_return')\n",
    "    print(p1_return_table)\n",
    "    selected_stocks = list(set(p1_predicted_return.columns).intersection(p1_return_table_pivot.columns))\n",
    "    # use the 1-year historical return table to calculate covariance matrix between selected stocks\n",
    "    p1_predicted_return = p1_predicted_return.loc[:, selected_stocks]\n",
    "    p1_return_table_pivot = p1_return_table_pivot.loc[:, selected_stocks]\n",
    "    S = risk_models.sample_cov(p1_return_table_pivot)\n",
    "    mu = p1_predicted_return.T.values\n",
    "   # del S.index.name \n",
    "    # mean variance\n",
    "    ef_mean = EfficientFrontier(mu, S,weight_bounds=(0, 0.05))\n",
    "    # raw_weights_mean = ef_mean.max_sharpe()\n",
    "    raw_weights_mean = ef_mean.nonconvex_objective(\n",
    "        objective_functions.sharpe_ratio,\n",
    "        objective_args = (ef_mean.expected_returns, ef_mean.cov_matrix),\n",
    "        weights_sum_to_one = True\n",
    "    )\n",
    "    cleaned_weights_mean = ef_mean.clean_weights()\n",
    "    #print(raw_weights_mean)\n",
    "    #ef.portfolio_performance(verbose=True)\n",
    "    #print(\"cleaned_weights_mean: \", cleaned_weights_mean)\n",
    "\n",
    "    # minimum variance\n",
    "    ef_min = EfficientFrontier([0]*len(mu), S,weight_bounds=(0, 0.05))\n",
    "   # raw_weights_min = ef_min.max_sharpe()\n",
    "    raw_weights_min = ef_min.nonconvex_objective(\n",
    "        objective_functions.sharpe_ratio,\n",
    "        objective_args = (ef_min.expected_returns, ef_min.cov_matrix),\n",
    "        weights_sum_to_one = True\n",
    "    )\n",
    "    cleaned_weights_min = ef_min.clean_weights()\n",
    "    #print(cleaned_weights_min)\n",
    "    print(\"cleaned_weights_min: \", cleaned_weights_min)\n",
    "\n",
    "    idx = np.isin(p1_alldata.gvkey, selected_stocks)\n",
    "    p1_alldata[\"mean_weight\"] = 0\n",
    "    p1_alldata['mean_weight'][idx] = list(cleaned_weights_mean.values())\n",
    "    p1_alldata[\"min_weight\"] = 0\n",
    "    p1_alldata['min_weight'][idx] = list(cleaned_weights_min.values())\n",
    "    p1_alldata[\"equal_weight\"] = 0\n",
    "    p1_alldata['equal_weight'][idx] = np.ones(len(cleaned_weights_mean.values())) / len(cleaned_weights_mean.values())\n",
    "    #ef.portfolio_performance(verbose=True)\n",
    "    \n",
    "    stocks_weight_table = stocks_weight_table.append(pd.DataFrame(p1_alldata), ignore_index=True)\n",
    "    print(trade_date[i], \": Done\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3870, 6)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stocks_weight_table.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gvkey</th>\n",
       "      <th>predicted_return</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>mean_weight</th>\n",
       "      <th>min_weight</th>\n",
       "      <th>equal_weight</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1230</td>\n",
       "      <td>0.026920</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>0.00590</td>\n",
       "      <td>0.00531</td>\n",
       "      <td>0.005556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1678</td>\n",
       "      <td>0.013570</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>0.00572</td>\n",
       "      <td>0.00531</td>\n",
       "      <td>0.005556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1722</td>\n",
       "      <td>0.035988</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>0.00572</td>\n",
       "      <td>0.00532</td>\n",
       "      <td>0.005556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2574</td>\n",
       "      <td>0.035439</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>0.00549</td>\n",
       "      <td>0.00531</td>\n",
       "      <td>0.005556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2751</td>\n",
       "      <td>0.028170</td>\n",
       "      <td>2018-03-01</td>\n",
       "      <td>0.00572</td>\n",
       "      <td>0.00531</td>\n",
       "      <td>0.005556</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   gvkey  predicted_return  trade_date  mean_weight  min_weight  equal_weight\n",
       "0   1230          0.026920  2018-03-01      0.00590     0.00531      0.005556\n",
       "1   1678          0.013570  2018-03-01      0.00572     0.00531      0.005556\n",
       "2   1722          0.035988  2018-03-01      0.00572     0.00532      0.005556\n",
       "3   2574          0.035439  2018-03-01      0.00549     0.00531      0.005556\n",
       "4   2751          0.028170  2018-03-01      0.00572     0.00531      0.005556"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stocks_weight_table.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## save to excel or csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_mean = pd.DataFrame()\n",
    "df_mean['trade_date'] = stocks_weight_table['trade_date']\n",
    "df_mean['gvkey'] = stocks_weight_table['gvkey']\n",
    "df_mean['weights'] = stocks_weight_table['mean_weight']\n",
    "df_mean['predicted_return'] = stocks_weight_table['predicted_return']\n",
    "df_mean.to_excel(\"mean_weighted.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_min = pd.DataFrame()\n",
    "df_min['trade_date'] = stocks_weight_table['trade_date']\n",
    "df_min['gvkey'] = stocks_weight_table['gvkey']\n",
    "df_min['weights'] = stocks_weight_table['min_weight']\n",
    "df_min['predicted_return'] = stocks_weight_table['predicted_return']\n",
    "df_min.to_excel(\"minimum_weighted.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_equal = pd.DataFrame()\n",
    "df_equal['trade_date'] = stocks_weight_table['trade_date']\n",
    "df_equal['gvkey'] = stocks_weight_table['gvkey']\n",
    "df_equal['weights'] = stocks_weight_table['equal_weight']\n",
    "df_equal['predicted_return'] = stocks_weight_table['predicted_return']\n",
    "df_equal.to_excel(\"equally_weighted.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "vscode": {
   "interpreter": {
    "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
